Skip to content

Commit d08a26d

Browse files
committed
Jun 30
1 parent 99a3fbd commit d08a26d

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from collections import Counter
2+
3+
4+
class Solution:
5+
def findLHS(self, nums: list[int]) -> int:
6+
freq = Counter(nums)
7+
lhs = 0
8+
for num in freq.keys():
9+
if num + 1 in freq:
10+
lhs = max(lhs, freq[num] + freq[num + 1])
11+
return lhs
12+
13+
14+
def main():
15+
nums = [1, 3, 2, 2, 5, 2, 3, 7]
16+
assert Solution().findLHS(nums) == 5
17+
18+
nums = [1, 2, 3, 4]
19+
assert Solution().findLHS(nums) == 2
20+
21+
nums = [1, 1, 1, 1]
22+
assert Solution().findLHS(nums) == 0
23+
24+
25+
if __name__ == '__main__':
26+
main()

2025-06-June-LeetCoding-Challenge/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
| June 24 | [2200. Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | Solved |
3131
| June 25 | [2040. Kth Smallest Product of Two Sorted Arrays](https://leetcode.com/problems/kth-smallest-product-of-two-sorted-arrays/) | Hard | Unsolved |
3232
| June 26 | [2311. Longest Binary Subsequence Less Than or Equal to K](https://leetcode.com/problems/longest-binary-subsequence-less-than-or-equal-to-k/) | Medium | Unsolved |
33-
| June 27 | []() | | |
33+
| June 27 | [2014. Longest Subsequence Repeated k Times](https://leetcode.com/problems/longest-subsequence-repeated-k-times/) | Hard | Unsolved |
3434
| June 28 | []() | | |
3535
| June 29 | []() | | |
36-
| June 30 | []() | | |
36+
| June 30 | [594. Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence/) | Easy | Solved |
3737

3838

3939
## Summary
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
42-
| Easy | 4 | 4 | 0 |
42+
| Easy | 5 | 5 | 0 |
4343
| Medium | 11 | 7 | 4 |
44-
| Hard | 7 | 2 | 5 |
44+
| Hard | 8 | 2 | 6 |

0 commit comments

Comments
 (0)