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 64d0880 commit 3430490Copy full SHA for 3430490
longest-consecutive-sequence/PDKhan.cpp
@@ -0,0 +1,30 @@
1
+class Solution {
2
+ public:
3
+ int longestConsecutive(vector<int>& nums) {
4
+ int cnt = 1;
5
+ int max = 0;
6
+
7
+ if(nums.size() == 0)
8
+ return 0;
9
10
+ sort(nums.begin(), nums.end());
11
12
+ for(int i = 1; i < nums.size(); i++){
13
+ if(nums[i] == nums[i-1] + 1)
14
+ cnt++;
15
+ else if(nums[i] == nums[i-1])
16
+ continue;
17
+ else{
18
+ if(max < cnt)
19
+ max = cnt;
20
21
+ cnt = 1;
22
+ }
23
24
25
26
+ return cnt;
27
28
+ return max;
29
30
+ };
0 commit comments