Skip to content

Commit ed1e4f1

Browse files
committed
Update time and space complexity comments in longestConsecutive function
1 parent 388765f commit ed1e4f1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

longest-consecutive-sequence/gcount85.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414
4. return max_count
1515
1616
# Complexity
17-
- Time complexity: O(N)
17+
- Time complexity: O(N log N)
1818
19-
- Space complexity: O(1)
19+
- Space complexity: O(N)
2020
"""
2121

2222

2323
class Solution:
2424
def longestConsecutive(self, nums: List[int]) -> int:
25-
nums.sort()
25+
nums.sort() # Time complexity O(N log N), Space complexity O(N)
2626
max_count = 0
2727
count = 1
2828
prev = 0
29-
for n in nums[1:]:
29+
for n in nums[1:]: # Space complexity O(N)
3030
if n == nums[prev] + 1:
3131
count += 1
3232
elif n < nums[prev] or n > nums[prev] + 1:

0 commit comments

Comments
 (0)