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 388765f commit ed1e4f1Copy full SHA for ed1e4f1
1 file changed
longest-consecutive-sequence/gcount85.py
@@ -14,19 +14,19 @@
14
4. return max_count
15
16
# Complexity
17
-- Time complexity: O(N)
+- Time complexity: O(N log N)
18
19
-- Space complexity: O(1)
+- Space complexity: O(N)
20
"""
21
22
23
class Solution:
24
def longestConsecutive(self, nums: List[int]) -> int:
25
- nums.sort()
+ nums.sort() # Time complexity O(N log N), Space complexity O(N)
26
max_count = 0
27
count = 1
28
prev = 0
29
- for n in nums[1:]:
+ for n in nums[1:]: # Space complexity O(N)
30
if n == nums[prev] + 1:
31
count += 1
32
elif n < nums[prev] or n > nums[prev] + 1:
0 commit comments