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 380ebdd commit 58e53aaCopy full SHA for 58e53aa
longest-consecutive-sequence/samthekorean.py
@@ -0,0 +1,15 @@
1
+# TC : O(n) where n is the length of nums
2
+# SC : O(n) where n is the size of nums
3
+class Solution:
4
+ def longestConsecutive(self, nums: List[int]) -> int:
5
+ numSet = set(nums)
6
+ longest = 0
7
+
8
+ for n in nums:
9
+ # check whether its the start of the sequence
10
+ if (n - 1) not in numSet:
11
+ length = 0
12
+ while (n + length) in numSet:
13
+ length += 1
14
+ longest = max(length, longest)
15
+ return longest
0 commit comments