Skip to content

Commit 09bab7e

Browse files
committed
FEAT : solve #128
1 parent 3337224 commit 09bab7e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <set>
4+
5+
using namespace std;
6+
7+
class Solution {
8+
public:
9+
int longestConsecutive(vector<int>& nums) {
10+
set<int> s(nums.begin(), nums.end());
11+
int cnt = 0;
12+
int max = 0;
13+
14+
int i = *s.begin();
15+
for (set<int>::iterator iter = s.begin(); iter != s.end(); iter++)
16+
{
17+
cout << *iter << endl;
18+
if (*iter != i)
19+
{
20+
cnt = 1;
21+
i = *iter + 1;
22+
continue;
23+
}
24+
cnt++;
25+
i++;
26+
if (cnt > max)
27+
max = cnt;
28+
}
29+
return (max);
30+
}
31+
};

0 commit comments

Comments
 (0)