Skip to content

Commit af3cf9e

Browse files
committed
Time: 68 ms (91.33%), Space: 40 MB (66.81%) - LeetHub
1 parent c4bcd45 commit af3cf9e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int findLHS(vector<int>& nums) {
4+
unordered_map<int,int> mp;
5+
int n = nums.size();
6+
7+
for(auto x: nums)
8+
mp[x]++;
9+
10+
int mx = 0;
11+
for(auto x: mp){
12+
int f = x.first;
13+
14+
// both must exist
15+
if(mp.count(f + 1) > 0)
16+
mx = max(mx, mp[f] + mp[f + 1]);
17+
}
18+
19+
return mx;
20+
}
21+
};

0 commit comments

Comments
 (0)