标签:vector tco for pre span div begin return ase
class Solution { public: int longestConsecutive(vector<int>& nums) { unordered_set<int> s(nums.begin(), nums.end()); int res = 0; while (!s.empty()) { int p = *(s.begin()); s.erase(p); int cnt = 1; for (int i = 1; s.count(p+i); i++) { cnt++; s.erase(p+i); } for (int i = -1; s.count(p+i); i--) { cnt++; s.erase(p+i); } res = max(res, cnt); } return res; } };
128. Longest Consecutive Sequence
标签:vector tco for pre span div begin return ase
原文地址:https://www.cnblogs.com/JTechRoad/p/9063381.html