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 ce9b140 commit 4f0c677Copy full SHA for 4f0c677
1 file changed
longest-consecutive-sequence/juhui-jeong.java
@@ -0,0 +1,25 @@
1
+class Solution {
2
+ public int longestConsecutive(int[] nums) {
3
+ if(nums == null || nums.length == 0) return 0;
4
+ Arrays.sort(nums);
5
+
6
+ int maxLen = 1;
7
+ int curLen = 1;
8
9
+ for(int i = 1; i < nums.length; i++) {
10
+ if (nums[i] == nums[i-1]) {
11
+ // 중복 건너뛰기
12
+ continue;
13
+ }
14
15
+ if (nums[i] == nums[i-1] +1) {
16
+ curLen++;
17
+ } else {
18
+ maxLen = Math.max(maxLen, curLen);
19
+ curLen = 1;
20
21
22
23
+ return Math.max(maxLen, curLen);
24
25
+}
0 commit comments