20230317 顺利通过
20230319 顺利通过
20230403 if(!hashset.count(h - 1))
原题解
题目
约束
题解
class Solution {
public:
int longestConsecutive(vector<int>& nums) {
int ans = 0;
unordered_set<int> hashSet;
for(auto num : nums){
hashSet.insert(num);
}
for(auto num : hashSet){
if(!hashSet.count(num - 1)){
int cur = num;
int len = 1;
while(hashSet.count(cur + 1)){
cur += 1;
len += 1;
}
ans = max(ans, len);
}
}
return ans;
}
};