Skip to content

[Leo] 14th Week solutions #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2024
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
25 changes: 25 additions & 0 deletions set-matrix-zeroes/Leo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
if not matrix:
return []
Comment on lines +6 to +7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 <= m, n <= 200

nit: λ¬Έμ œμ— μœ„μ™€ 같은 μ œν•œμ‚¬ν•­μ΄ μ£Όμ–΄μ‘ŒμœΌλ‹ˆ μ΄λŸ¬ν•œ κ²€μ‚¬λŠ” λΆˆν•„ν•œ 것 κ°™μŠ΅λ‹ˆλ‹Ή~


m = len(matrix)
n = len(matrix[0])

zeroes_row = [False] * m
zeroes_col = [False] * n
for row in range(m):
for col in range(n):
if matrix[row][col] == 0:
zeroes_row[row] = True
zeroes_col[col] = True

for row in range(m):
for col in range(n):
if zeroes_row[row] or zeroes_col[col]:
matrix[row][col] = 0

## TC: O(mn), SC: O(m+n)
34 changes: 34 additions & 0 deletions spiral-matrix/Leo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
res = []
while matrix:
res.extend(matrix.pop(0))
matrix = [*zip(*matrix)][::-1]
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boom-mind-blown-gif

return res

## TC: O(m * n), SC: O(m * n)
## This sloution is kinda tricky and has higher SC than the below one

# res = []
# if len(matrix) == 0:
# return res
# row_begin = 0
# col_begin = 0
# row_end = len(matrix)-1
# col_end = len(matrix[0])-1
# while (row_begin <= row_end and col_begin <= col_end):
# for i in range(col_begin,col_end+1):
# res.append(matrix[row_begin][i])
# row_begin += 1
# for i in range(row_begin,row_end+1):
# res.append(matrix[i][col_end])
# col_end -= 1
# if (row_begin <= row_end):
# for i in range(col_end,col_begin-1,-1):
# res.append(matrix[row_end][i])
# row_end -= 1
# if (col_begin <= col_end):
# for i in range(row_end,row_begin-1,-1):
# res.append(matrix[i][col_begin])
# col_begin += 1
# return res
6 changes: 6 additions & 0 deletions sum-of-two-integers/Leo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Solution:
def getSum(self, a: int, b: int) -> int:
return add(a,b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

νŒŒμ΄μ¬μ— 이런 λ‚΄μž₯ ν•¨μˆ˜λ„ μžˆμ—ˆλ˜κ°€μš”? πŸ˜†

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ„΅..γ…‹γ…‹ 쑰금 사기성이 짙은 μ†”λ£¨μ…˜μ΄μ§€λ§Œμš” 🀣

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ•—.. λ‹€μ‹œ μ°Ύμ•„λ³΄λ‹ˆ 이거 빌트인이 μ•„λ‹ˆλ„€μš”! λ¦¬νŠΈμ½”λ“œκ°€ μ–΄μ§€κ°„ν•œ λͺ¨λ“ˆμ„ 이미 μž„ν¬νŠΈ ν•΄λ†”μ„œ μ œκ°€ 아무생각없이 μ¨λ²„λ Έλ„€μš” γ… γ… γ…‹γ…‹


## I love this solution :P
## TC: O(1), SC: O(1)