We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3fb050b commit 12c8c7cCopy full SHA for 12c8c7c
solution/0128.Longest Consecutive Sequence/Solution.java
@@ -0,0 +1,18 @@
1
+class Solution {
2
+ public int longestConsecutive(int[] nums) {
3
+ if (nums.length == 0) return 0;
4
+ Arrays.sort(nums);
5
+ int start = 0, casch = nums[0], longest = 0;
6
+ for (int i = 1; i < nums.length; i++) {
7
+ int nc = nums[i] , con = nc - casch;
8
+ if (con == 0) {
9
+ start++;
10
+ } else if (con != 1) {
11
+ longest = Math.max(i - start, longest);
12
+ start = i;
13
+ }
14
+ casch = nc;
15
16
+ return Math.max(nums.length - start, longest);
17
18
+}
0 commit comments