We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0d8c4b8 commit 394d5f3Copy full SHA for 394d5f3
longest-consecutive-sequence/dylan-jung.cpp
@@ -0,0 +1,22 @@
1
+class Solution {
2
+public:
3
+ int longestConsecutive(vector<int>& nums) {
4
+ auto s = unordered_set<int>();
5
+ for(int it : nums) {
6
+ s.insert(it);
7
+ }
8
+
9
+ int m = 0;
10
+ for(int it : s) {
11
+ if(s.count(it-1) > 0) continue;
12
13
+ int cnt = 0;
14
+ while(s.count(it+cnt) > 0){
15
+ cnt++;
16
17
+ m = max(m, cnt);
18
19
20
+ return m;
21
22
+};
0 commit comments