Skip to content

Commit a9593e8

Browse files
committed
[main] longest-consecutive-sequence solution
1 parent 190b011 commit a9593e8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def longestConsecutive(self, nums: List[int]) -> int:
3+
if len(nums) <= 1:
4+
return len(nums)
5+
6+
result = [1] * len(nums)
7+
8+
# 중복 제거 후 정렬
9+
nums = sorted(list(set(nums)))
10+
11+
# 연속된 숫자 찾기
12+
for i in range(1, len(nums)):
13+
if nums[i] - 1 == nums[i-1]:
14+
result[i] = result[i-1] + 1
15+
16+
return max(result)

0 commit comments

Comments
 (0)