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 3e89531 commit f51e31cCopy full SHA for f51e31c
1 file changed
longest-consecutive-sequence/doh6077.py
@@ -1,4 +1,5 @@
1
# 배열을 정렬하고 포인터를 두개 사용
2
+"""
3
class Solution:
4
def longestConsecutive(self, nums: List[int]) -> int:
5
if not nums:
@@ -32,10 +33,32 @@ def longestConsecutive(self, nums: List[int]) -> int:
32
33
r += 1
34
35
return longest
36
37
+from typing import List
38
39
+class Solution:
40
+ def longestConsecutive(self, nums: List[int]) -> int:
41
+ if len(nums) <= 1:
42
+ return len(nums)
43
+
44
+ nums.sort()
45
+ r = 1
46
+ curr = nums[0]
47
+ count = 1
48
+ max_count = 1
49
50
+ while r < len(nums):
51
+ if nums[r] == curr:
52
+ r += 1
53
+ continue
54
55
+ if nums[r] == curr + 1:
56
+ count += 1
57
+ else:
58
59
60
+ curr = nums[r]
61
+ max_count = max(max_count, count)
62
63
-nums = [1,2,3,5]
-nums.sort()
-print(nums)
64
+ return max_count
0 commit comments