File tree 3 files changed +65
-0
lines changed 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def setZeroes (self , matrix : List [List [int ]]) -> None :
3
+ """
4
+ Do not return anything, modify matrix in-place instead.
5
+ """
6
+ if not matrix :
7
+ return []
8
+
9
+ m = len (matrix )
10
+ n = len (matrix [0 ])
11
+
12
+ zeroes_row = [False ] * m
13
+ zeroes_col = [False ] * n
14
+ for row in range (m ):
15
+ for col in range (n ):
16
+ if matrix [row ][col ] == 0 :
17
+ zeroes_row [row ] = True
18
+ zeroes_col [col ] = True
19
+
20
+ for row in range (m ):
21
+ for col in range (n ):
22
+ if zeroes_row [row ] or zeroes_col [col ]:
23
+ matrix [row ][col ] = 0
24
+
25
+ ## TC: O(mn), SC: O(m+n)
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def spiralOrder (self , matrix : List [List [int ]]) -> List [int ]:
3
+ res = []
4
+ while matrix :
5
+ res .extend (matrix .pop (0 ))
6
+ matrix = [* zip (* matrix )][::- 1 ]
7
+ return res
8
+
9
+ ## TC: O(m * n), SC: O(m * n)
10
+ ## This sloution is kinda tricky and has higher SC than the below one
11
+
12
+ # res = []
13
+ # if len(matrix) == 0:
14
+ # return res
15
+ # row_begin = 0
16
+ # col_begin = 0
17
+ # row_end = len(matrix)-1
18
+ # col_end = len(matrix[0])-1
19
+ # while (row_begin <= row_end and col_begin <= col_end):
20
+ # for i in range(col_begin,col_end+1):
21
+ # res.append(matrix[row_begin][i])
22
+ # row_begin += 1
23
+ # for i in range(row_begin,row_end+1):
24
+ # res.append(matrix[i][col_end])
25
+ # col_end -= 1
26
+ # if (row_begin <= row_end):
27
+ # for i in range(col_end,col_begin-1,-1):
28
+ # res.append(matrix[row_end][i])
29
+ # row_end -= 1
30
+ # if (col_begin <= col_end):
31
+ # for i in range(row_end,row_begin-1,-1):
32
+ # res.append(matrix[i][col_begin])
33
+ # col_begin += 1
34
+ # return res
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def getSum (self , a : int , b : int ) -> int :
3
+ return add (a ,b )
4
+
5
+ ## I love this solution :P
6
+ ## TC: O(1), SC: O(1)
You can’t perform that action at this time.
0 commit comments