Skip to content

Commit da56f83

Browse files
committed
fix file conent for m128
1 parent 1af5cfb commit da56f83

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

my-submissions/m128 v2.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1+
# O(n) solution babyyyy
2+
13
class Solution:
24
def longestConsecutive(self, nums: List[int]) -> int:
35
if len(nums) == 0 :
46
return 0
5-
7+
68
vals = set(nums) # O(n) creation, O(1) lookups
79

810
maxx = 0
9-
for val in vals: # O(n) looping
10-
if val - 1 in vals: # not start of sequence
11-
continue
12-
13-
cnter = 1
14-
while val + cnter in vals :
15-
cnter += 1
11+
while vals :
12+
left = right = vals.pop()
13+
curr = 1
14+
while left - 1 in vals :
15+
left -= 1
16+
curr += 1
17+
vals.remove(left)
18+
while right + 1 in vals :
19+
right += 1
20+
curr += 1
21+
vals.remove(right)
1622

17-
maxx = max(maxx, cnter)
23+
maxx = max(maxx, curr)
1824

1925
return maxx

0 commit comments

Comments
 (0)