#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
using namespace std;
int longestConsecutive(vector<int>& nums) {
if(nums.size()==0) return 0;
sort(nums.begin(),nums.end());
int res=1;
int count=1;
for(int i=0; i<nums.size()-1; i++){
if(nums[i+1]-nums[i] == 1){
count++;
}else if(nums[i+1]-nums[i] > 1){
res=max(res,count);
count=1;
}
res=max(res,count);
}
return res;
}
int longestConsecutive2(vector<int>& nums) {
set<int> s;
for(int n : nums)
s.insert(n);
int maxLen = 1, curLen = 1;
for(int n : s){
if(s.find(n-1) != s.end()){
curLen++;
}else{
maxLen = max(maxLen, curLen);
curLen = 1;
}
}
return max(maxLen, curLen);
}
int longestConsecutive3(vector<int>& nums) {
unordered_set<int> s(nums.begin(), nums.end());
int maxLen = 0;
for (int num:nums) {
if (s.count(num - 1))continue;
else
{
int len = 1;
while (s.count(num+1))
{
num++;
len++;
}
maxLen = max(maxLen, len);
}
}
return maxLen;
}
int main() {
std::cout << "Hello, World!" << std::endl;
vector<int> vect={100, 4, 200, 1, 3, 2,300,301,302,303,304,305};
cout << longestConsecutive(vect);
return 0;
}