Skip to content

Commit a62bcbf

Browse files
Zanger67/leetcodeZanger67/leetcode
Zanger67/leetcode
authored and
Zanger67/leetcode
committed
Updated markdown files
1 parent da56f83 commit a62bcbf

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

Diff for: markdowns/Questions_By_Code_Length.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Calculations are based on the code files's byte sizes.
104104
| 2 | [Add Two Numbers](<https://leetcode.com/problems/add-two-numbers>) | Medium | N150 | [solution](<_2. Add Two Numbers.md>) | java | May 22, 2024 |
105105
| 430 | [Flatten a Multilevel Doubly Linked List](<https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list>) | Medium | | [solution](<_430. Flatten a Multilevel Doubly Linked List.md>) | cpp, java | Jun 27, 2024 |
106106
| 239 | [Sliding Window Maximum](<https://leetcode.com/problems/sliding-window-maximum>) | Hard | N150 | [solution](<_239. Sliding Window Maximum.md>) | py | Jun 04, 2024 |
107+
| 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 |
107108
| 103 | [Binary Tree Zigzag Level Order Traversal](<https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal>) | Medium | | [solution](<_103. Binary Tree Zigzag Level Order Traversal.md>) | py | Jul 03, 2024 |
108109
| 3306 | [Count of Substrings Containing Every Vowel and K Consonants II](<https://leetcode.com/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii>) | Medium | Daily | [solution](<_3306. Count of Substrings Containing Every Vowel and K Consonants II.md>) | py | Mar 10, 2025 |
109110
| 645 | [Set Mismatch](<https://leetcode.com/problems/set-mismatch>) | Easy | | [solution](<_645. Set Mismatch.md>) | java, py | Jun 01, 2024 |
@@ -117,7 +118,6 @@ Calculations are based on the code files's byte sizes.
117118
| 40 | [Combination Sum II](<https://leetcode.com/problems/combination-sum-ii>) | Medium | Daily, N150 | [solution](<_40. Combination Sum II.md>) | py | Aug 13, 2024 |
118119
| 611 | [Valid Triangle Number](<https://leetcode.com/problems/valid-triangle-number>) | Medium | | [solution](<_611. Valid Triangle Number.md>) | py | May 22, 2024 |
119120
| 3229 | Weekly Contest 407 - q4 - [Minimum Operations to Make Array Equal to Target](<https://leetcode.com/problems/minimum-operations-to-make-array-equal-to-target>) | Hard | Contest | [solution](<_3229. Minimum Operations to Make Array Equal to Target.md>) | py | Jul 21, 2024 |
120-
| 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 |
121121
| 381 | [Insert Delete GetRandom O(1) - Duplicates allowed](<https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed>) | Hard | | [solution](<_381. Insert Delete GetRandom O(1) - Duplicates allowed.md>) | java | Jul 06, 2024 |
122122
| 419 | [Battleships in a Board](<https://leetcode.com/problems/battleships-in-a-board>) | Medium | | [solution](<_419. Battleships in a Board.md>) | c, py | Jun 24, 2024 |
123123
| 353 | [Design Snake Game](<https://leetcode.com/problems/design-snake-game>) | Medium | | [solution](<_353. Design Snake Game.md>) | py | Jun 28, 2024 |

Diff for: markdowns/_128. Longest Consecutive Sequence.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,29 @@ class Solution:
6767

6868
#### [m128 v2.py](<../my-submissions/m128 v2.py>)
6969
```Python
70+
# O(n) solution babyyyy
71+
7072
class Solution:
7173
def longestConsecutive(self, nums: List[int]) -> int:
7274
if len(nums) == 0 :
7375
return 0
74-
76+
7577
vals = set(nums) # O(n) creation, O(1) lookups
7678

7779
maxx = 0
78-
for val in vals: # O(n) looping
79-
if val - 1 in vals: # not start of sequence
80-
continue
81-
82-
cnter = 1
83-
while val + cnter in vals :
84-
cnter += 1
85-
86-
maxx = max(maxx, cnter)
80+
while vals :
81+
left = right = vals.pop()
82+
curr = 1
83+
while left - 1 in vals :
84+
left -= 1
85+
curr += 1
86+
vals.remove(left)
87+
while right + 1 in vals :
88+
right += 1
89+
curr += 1
90+
vals.remove(right)
91+
92+
maxx = max(maxx, curr)
8793

8894
return maxx
8995

0 commit comments

Comments
 (0)