Skip to content

Commit b0cdabe

Browse files
committed
feat: update mismatch
1 parent 43cf917 commit b0cdabe

File tree

7 files changed

+69
-11
lines changed

7 files changed

+69
-11
lines changed

leetcode/climbing_stairs/solution.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ class Solution:
22

33
# Time: O(n)
44
# Space: O(1)
5+
# This follows Fibonacci pattern
6+
# Standard Fib: F(0)=0, F(1)=1, F(2)=1, F(3)=2, F(4)=3, F(5)=5...
57
def climb_stairs(self, n: int) -> int:
6-
7-
# This follows Fibonacci pattern
8-
# Standard Fib: F(0)=0, F(1)=1, F(2)=1, F(3)=2, F(4)=3, F(5)=5...
98
if n <= 2:
109
return n
1110

leetcode/first_bad_version/solution.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
class Solution:
22

3-
# Time: O(?)
4-
# Space: O(?)
53
def __init__(self, first_bad: int = 1) -> None:
64
self.is_bad_version = lambda version: version >= first_bad
75

leetcode/min_stack/solution.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,16 @@ def top(self) -> int:
2828
# Space: O(1)
2929
def get_min(self) -> int:
3030
return self.min_stack[-1]
31+
32+
33+
# Example walkthrough: push(-2), push(0), push(-3), getMin(), pop(), top(), getMin()
34+
#
35+
# Initial: stack=[], min_stack=[]
36+
#
37+
# push(-2): stack=[-2], min_stack=[-2] (first element, add to both)
38+
# push(0): stack=[-2,0], min_stack=[-2] (0 > -2, don't add to min_stack)
39+
# push(-3): stack=[-2,0,-3], min_stack=[-2,-3] (-3 <= -2, add to min_stack)
40+
# getMin(): return -3 (top of min_stack)
41+
# pop(): stack=[-2,0], min_stack=[-2] (-3 was min, remove from both stacks)
42+
# top(): return 0 (top of main stack)
43+
# getMin(): return -2 (top of min_stack after pop)

leetcode/minimum_height_trees/solution.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from collections import defaultdict, deque
2+
3+
14
class Solution:
25

36
# Time: O(V)
47
# Space: O(V)
58
def find_min_height_trees(self, n: int, edges: list[list[int]]) -> list[int]:
6-
from collections import defaultdict, deque
7-
89
if n == 1:
910
return [0]
1011

leetcode/rotting_oranges/solution.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from collections import deque
2+
3+
14
class Solution:
25

36
# Time: O(m*n)
47
# Space: O(m*n)
58
def oranges_rotting(self, grid: list[list[int]]) -> int:
6-
from collections import deque
7-
89
EMPTY, FRESH, ROTTEN = 0, 1, 2
910
_ = EMPTY
1011

leetcode/serialize_and_deserialize_binary_tree/solution.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,48 @@ def dfs():
3939
return node
4040

4141
return dfs()
42+
43+
44+
# Binary Tree Serialization Techniques
45+
46+
# Example Tree:
47+
# 1
48+
# / \
49+
# 2 3
50+
# / \
51+
# 4 5
52+
53+
# 1. Preorder with Null Markers (This Implementation)
54+
# Visit: root → left → right, mark nulls with '#'
55+
# Result: "1,2,#,#,3,4,#,#,5,#,#"
56+
# Pros: Self-contained, unambiguous, O(n) reconstruction
57+
# Cons: Longer string due to null markers
58+
59+
# 2. Level-order (BFS) with Null Markers
60+
# Visit level by level, mark nulls with '#'
61+
# Result: "1,2,3,#,#,4,5"
62+
# Pros: Simple format like preorder, level-by-level intuitive
63+
# Cons: Still requires queue processing
64+
65+
# 3. Postorder with Null Markers
66+
# Visit: left → right → root
67+
# Result: "#,#,2,#,#,4,#,#,5,3,1"
68+
# Pros: Bottom-up reconstruction
69+
# Cons: Less intuitive than preorder
70+
71+
# 4. Inorder + Preorder (Two Arrays)
72+
# Inorder: [2,1,4,3,5], Preorder: [1,2,3,4,5]
73+
# Pros: Works for any binary tree structure
74+
# Cons: Requires two arrays, only works with unique values
75+
76+
# 5. Parenthetical Preorder
77+
# Same traversal as #1 but with parentheses format: value(left)(right)
78+
# Result: "1(2()())(3(4()())(5()()))"
79+
# Pros: Human readable structure, shows nesting clearly
80+
# Cons: Complex parsing, verbose
81+
82+
# 6. Parenthetical Postorder
83+
# Same traversal as #3 but with parentheses format: (left)(right)value
84+
# Result: "(()()2)((()()4)(()()5)3)1"
85+
# Pros: Bottom-up readable structure
86+
# Cons: Even more complex parsing

leetcode/zero_one_matrix/solution.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from collections import deque
2+
3+
14
class Solution:
25

36
# Time: O(m * n)
47
# Space: O(m * n)
58
def update_matrix(self, mat: list[list[int]]) -> list[list[int]]:
6-
from collections import deque
7-
89
UNSEEN = -1
910
m, n = len(mat), len(mat[0])
1011
queue: deque[tuple[int, int]] = deque()

0 commit comments

Comments
 (0)