Skip to content

Commit f5626a4

Browse files
Zanger67/leetcodeZanger67/leetcode
Zanger67/leetcode
authored and
Zanger67/leetcode
committed
Updated markdown files
1 parent 94aaf92 commit f5626a4

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

markdowns/Questions_By_Code_Length.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ Calculations are based on the code files's byte sizes.
214214
| 1184 | [Distance Between Bus Stops](<https://leetcode.com/problems/distance-between-bus-stops>) | Easy | | [solution](<_1184. Distance Between Bus Stops.md>) | py | May 31, 2024 |
215215
| 362 | [Design Hit Counter](<https://leetcode.com/problems/design-hit-counter>) | Medium | | [solution](<_362. Design Hit Counter.md>) | py | Oct 24, 2024 |
216216
| 90 | [Subsets II](<https://leetcode.com/problems/subsets-ii>) | Medium | N150 | [solution](<_90. Subsets II.md>) | py | Jul 03, 2024 |
217+
| 128 | [Longest Consecutive Sequence](<https://leetcode.com/problems/longest-consecutive-sequence>) | Medium | B75, N150 | [solution](<_128. Longest Consecutive Sequence.md>) | java, py | Jun 13, 2024 |
217218
| 1730 | [Shortest Path to Get Food](<https://leetcode.com/problems/shortest-path-to-get-food>) | Medium | Weekly Premium | [solution](<_1730. Shortest Path to Get Food.md>) | py | Jun 26, 2024 |
218219
| 1530 | [Number of Good Leaf Nodes Pairs](<https://leetcode.com/problems/number-of-good-leaf-nodes-pairs>) | Medium | Daily | [solution](<_1530. Number of Good Leaf Nodes Pairs.md>) | py | Jul 18, 2024 |
219220
| 1823 | [Find the Winner of the Circular Game](<https://leetcode.com/problems/find-the-winner-of-the-circular-game>) | Medium | Daily | [solution](<_1823. Find the Winner of the Circular Game.md>) | c, cpp, java, js, py | Jul 08, 2024 |
@@ -226,7 +227,6 @@ Calculations are based on the code files's byte sizes.
226227
| 946 | [Validate Stack Sequences](<https://leetcode.com/problems/validate-stack-sequences>) | Medium | | [solution](<_946. Validate Stack Sequences.md>) | c, py | Jun 12, 2024 |
227228
| 211 | [Design Add and Search Words Data Structure](<https://leetcode.com/problems/design-add-and-search-words-data-structure>) | Medium | B75, N150 | [solution](<_211. Design Add and Search Words Data Structure.md>) | py | Jun 27, 2024 |
228229
| 1020 | [Number of Enclaves](<https://leetcode.com/problems/number-of-enclaves>) | Medium | | [solution](<_1020. Number of Enclaves.md>) | py | Jun 26, 2024 |
229-
| 128 | [Longest Consecutive Sequence](<https://leetcode.com/problems/longest-consecutive-sequence>) | Medium | B75, N150 | [solution](<_128. Longest Consecutive Sequence.md>) | java, py | Jun 13, 2024 |
230230
| 141 | [Linked List Cycle](<https://leetcode.com/problems/linked-list-cycle>) | Easy | B75, N150 | [solution](<_141. Linked List Cycle.md>) | c, py | Jun 04, 2024 |
231231
| 61 | [Rotate List](<https://leetcode.com/problems/rotate-list>) | Medium | | [solution](<_61. Rotate List.md>) | py | Jun 22, 2024 |
232232
| 2852 | [Sum of Remoteness of All Cells](<https://leetcode.com/problems/sum-of-remoteness-of-all-cells>) | Medium | Weekly Premium | [solution](<_2852. Sum of Remoteness of All Cells.md>) | py | Jan 23, 2025 |

markdowns/_128. Longest Consecutive Sequence.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
> *First completed : June 13, 2024*
1010
>
11-
> *Last updated : July 01, 2024*
11+
> *Last updated : March 12, 2025*
1212
1313
------
1414

@@ -57,25 +57,27 @@ class Solution {
5757
### Python
5858
#### [m128.py](<../my-submissions/m128.py>)
5959
```Python
60-
# O(n) solution babyyyy
61-
6260
class Solution:
6361
def longestConsecutive(self, nums: List[int]) -> int:
6462
if len(nums) == 0 :
6563
return 0
66-
64+
6765
vals = set(nums) # O(n) creation, O(1) lookups
6866

6967
maxx = 0
70-
for val in vals: # O(n) looping
71-
if val - 1 in vals: # not start of sequence
72-
continue
73-
74-
cnter = 1
75-
while val + cnter in vals :
76-
cnter += 1
77-
78-
maxx = max(maxx, cnter)
68+
while vals :
69+
left = right = vals.pop()
70+
curr = 1
71+
while left - 1 in vals :
72+
left -= 1
73+
curr += 1
74+
vals.remove(left)
75+
while right + 1 in vals :
76+
right += 1
77+
curr += 1
78+
vals.remove(right)
79+
80+
maxx = max(maxx, curr)
7981

8082
return maxx
8183

0 commit comments

Comments
 (0)