class Solution {
public:
int longestConsecutive(vector<int>& nums) {
unordered_set<int> s(nums.begin(), nums.end());
int best = 0;
for (int x : s) {
if (s.find(x - 1) == s.end()) {
int curr = x + 1;
while (s.find(curr) != s.end()) curr++;
best = max(best, curr - x);
}
}
return best;
}
};