Skip to content

Commit 4b46c37

Browse files
committed
longest consecutive sequence solution
1 parent 782fd83 commit 4b46c37

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# @lc app=leetcode id=128 lang=python3
3+
#
4+
# [128] Longest Consecutive Sequence
5+
#
6+
from typing import List
7+
# @lc code=start
8+
class Solution:
9+
def longestConsecutive(self, nums: List[int]) -> int:
10+
nums.sort()
11+
long=0
12+
13+
leng=1
14+
for i in range(len(nums)-1):
15+
if nums[i]==nums[i+1]:
16+
continue
17+
if nums[i]+1==nums[i+1]:
18+
leng+=1
19+
else:
20+
long=max(long,leng)
21+
leng=1
22+
# 아래를 추가해야 for문 다 돌았을 때 leng이 최고인 경우 반영
23+
long=max(long,leng)
24+
return long
25+
26+
27+
# @lc code=end
28+

top-k-frequent-elements/6kitty.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ def topKFrequent(self, nums: List[int], k: int) -> List[int]:
2020
return ssol
2121

2222

23-
24-
25-
2623

2724
# @lc code=end
2825

0 commit comments

Comments
 (0)