0128.Longest Consecutive Sequence
class Solution {
public:
int longestConsecutive(vector<int>& nums) {
unordered_set<int> set1;
int result = 0;
for(int& num : nums){
set1.insert(num);
}
for(int& num : nums){
int start;
if(set1.find(num-1) == set1.end()){
start = num;
}
int distance = 0;
while(set1.find(start) != set1.end()){
start = start + 1;
distance++;
}
result = max(result, distance);
}
return result;
}
};