-
-
Notifications
You must be signed in to change notification settings - Fork 195
[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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 [] | ||
|
||
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) |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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 |
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. νμ΄μ¬μ μ΄λ° λ΄μ₯ ν¨μλ μμλκ°μ? π There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. λ΅..γ γ μ‘°κΈ μ¬κΈ°μ±μ΄ μ§μ μ루μ μ΄μ§λ§μ π€£ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ.. λ€μ μ°Ύμ보λ μ΄κ±° λΉνΈμΈμ΄ μλλ€μ! 리νΈμ½λκ° μ΄μ§κ°ν λͺ¨λμ μ΄λ―Έ μν¬νΈ ν΄λμ μ κ° μ무μκ°μμ΄ μ¨λ²λ Έλ€μ γ γ γ γ |
||
|
||
## I love this solution :P | ||
## TC: O(1), SC: O(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: λ¬Έμ μ μμ κ°μ μ νμ¬νμ΄ μ£Όμ΄μ‘μΌλ μ΄λ¬ν κ²μ¬λ λΆνν κ² κ°μ΅λλΉ~