Skip to content

Commit 57b3b64

Browse files
committed
Add documentation and updates to 128
1 parent f5626a4 commit 57b3b64

File tree

4 files changed

+51
-23
lines changed

4 files changed

+51
-23
lines changed

my-submissions/m128 v1.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# O(n) solution babyyyy
2+
3+
class Solution:
4+
def longestConsecutive(self, nums: List[int]) -> int:
5+
if len(nums) == 0 :
6+
return 0
7+
8+
vals = set(nums) # O(n) creation, O(1) lookups
9+
10+
maxx = 0
11+
for val in vals: # O(n) looping
12+
if val - 1 in vals: # not start of sequence
13+
continue
14+
15+
cnter = 1
16+
while val + cnter in vals :
17+
cnter += 1
18+
19+
maxx = max(maxx, cnter)
20+
21+
return maxx

my-submissions/m128 v2.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def longestConsecutive(self, nums: List[int]) -> int:
3+
if len(nums) == 0 :
4+
return 0
5+
6+
vals = set(nums) # O(n) creation, O(1) lookups
7+
8+
maxx = 0
9+
for val in vals: # O(n) looping
10+
if val - 1 in vals: # not start of sequence
11+
continue
12+
13+
cnter = 1
14+
while val + cnter in vals :
15+
cnter += 1
16+
17+
maxx = max(maxx, cnter)
18+
19+
return maxx

my-submissions/m128.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## m128 v1
2+
3+
My initial attempt that was successful but inefficient. Achieved around a 350ms runtime.
4+
5+
## m128 java
6+
7+
Second attempt that was much more successful and achieved a reasonable runtim
8+
9+
## m128 v2
10+
11+
2nd python attempt that implemented a set removal optimization to save redundancy that brought the python version to the same runtime level as java.

my-submissions/m128.py

-23
This file was deleted.

0 commit comments

Comments
 (0)