Skip to content

Commit 4f0c677

Browse files
committed
WEEK 1 Solutions
1 parent ce9b140 commit 4f0c677

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)