Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions container-with-most-water/jeldo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
# O(n), n = len(height)
def maxArea(self, height: list[int]) -> int:
max_amount = 0
l, r = 0, len(height) - 1
while l < r:
amount = min(height[l], height[r]) * (r - l)
max_amount = max(max_amount, amount)
if height[l] < height[r]:
l += 1
else:
r -= 1
return max_amount
18 changes: 18 additions & 0 deletions spiral-matrix/jeldo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
# O(m*n), m = len(row), n = len(column)
def spiralOrder(self, m: list[list[int]]) -> list[int]:
dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)]
result = []
visited = set()
heading, count = 0, 0
r, c = 0, 0
while count < len(m) * len(m[0]):
result.append(m[r][c])
visited.add((r, c))
count += 1
next_r, next_c = r + dirs[heading][0], c + dirs[heading][1]
if not (0 <= next_r < len(m) and 0 <= next_c < len(m[0])) or (next_r, next_c) in visited:
heading = (heading + 1) % 4
next_r, next_c = r + dirs[heading][0], c + dirs[heading][1]
r, c = next_r, next_c
return result
17 changes: 17 additions & 0 deletions valid-parentheses/jeldo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution:
# O(n), n = len(s)
def isValid(self, s: str) -> bool:
parentheses = {
"(": ")",
"]": "]",
"{": "}",
}
stack = []
for ch in s:
if ch in parentheses.keys():
stack.append(ch)
elif stack and ch == parentheses[stack[-1]]:
stack.pop()
else:
return False
return len(stack) == 0
Loading