intlongestConsecutive(vector<int>& nums){ unordered_set<int> s; s.insert(std::begin(nums), std::end(nums)); int res = 0; for (int num : s) { if (!s.count(num - 1)) { int cur = num; int len = 1; while (s.count(cur + 1)) { cur++; len++; } res = len > res ? len : res; } } return res; }