Skip to content

Commit 1de52da

Browse files
committed
longest consecutive sequence solution & added newline
1 parent ef71c9f commit 1de52da

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def longestConsecutive(self, nums: List[int]) -> int:
3+
if len(nums) == 0:
4+
return 0
5+
6+
nums = sorted(set(nums))
7+
8+
currLength = 1
9+
lastNum = nums[0]
10+
result = 1
11+
12+
for i in range(1, len(nums)):
13+
if nums[i] == lastNum + 1:
14+
currLength += 1
15+
else:
16+
currLength = 1
17+
18+
result = max(result, currLength)
19+
lastNum = nums[i]
20+
21+
return result
22+

product-of-array-except-self/yayyz.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ def productExceptSelf(self, nums: List[int]) -> List[int]:
1313
output[i] *= postfix
1414
postfix *= nums[i]
1515

16-
return output
16+
return output
17+

0 commit comments

Comments
 (0)