class Solution {
public:
int longestConsecutive(vector<int>& nums) {
unordered_set<int> s;
for(auto num: nums) {
s.insert(num);
}
int longestNum = 0;
for(auto num: s) {
if(!s.count(num - 1)) {
int curNum = num;
int stepTotal = 1;
while(s.count(curNum + 1)) {
curNum++;
stepTotal++;
}
longestNum = max(longestNum, stepTotal);
}
}
return longestNum;
}
};
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!