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 6d16bae commit 6b23e03Copy full SHA for 6b23e03
longestConsecutiveSubseq.java
@@ -0,0 +1,27 @@
1
+class Solution {
2
+ public int longestConsecutive(int[] nums) {
3
+ if(nums.length==0)
4
+ return 0;
5
+ if(nums.length==1)
6
+ return 1;
7
+ Arrays.sort(nums);
8
+ int count = 1;
9
+ int maxCount =1;
10
+ for(int i=1;i<nums.length;i++){
11
+ if((nums[i-1]==nums[i])){
12
+ continue;
13
+ }
14
+ else if(nums[i-1]+1==nums[i]){
15
+ count++;
16
+ //System.out.println(arr[i-1]);
17
+ }else{
18
+ count = 1;
19
20
+
21
+ if(count>maxCount)
22
+ maxCount = count;
23
24
+ return maxCount;
25
26
27
+}
0 commit comments