File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Solution:
3
+ 1) matrix๋ฅผ ์ํํ๋ฉด์ 0์ ์ฐพ๋๋ค.
4
+ 2) 0์ผ ๊ฒฝ์ฐ rows, cols set์ ๊ฐ ์ธ๋ฑ์ค๋ฅผ ๋ฃ๋๋ค.
5
+ 3) rows, cols ๋ฅผ ์ํํ๋ฉด์ ํด๋นํ๋ row, col์ 0์ผ๋ก ๋ง๋ค์ด์ค๋ค.
6
+ Time: O(nm) = O(nm) (์ํ) + ์ต๋ O(nm) + ์ต๋ O(nm)
7
+ Space: O(n + m)
8
+ """
9
+
10
+
11
+ class Solution :
12
+ def setZeroes (self , matrix : List [List [int ]]) -> None :
13
+ """
14
+ Do not return anything, modify matrix in-place instead.
15
+ """
16
+ ROWS , COLS = len (matrix ), len (matrix [0 ])
17
+ rows = set ()
18
+ cols = set ()
19
+ for i in range (ROWS ):
20
+ for j in range (COLS ):
21
+ if matrix [i ][j ] == 0 :
22
+ rows .add (i )
23
+ cols .add (j )
24
+
25
+ for i in rows :
26
+ for j in range (COLS ):
27
+ matrix [i ][j ] = 0
28
+
29
+ for j in cols :
30
+ for i in range (ROWS ):
31
+ matrix [i ][j ] = 0
You canโt perform that action at this time.
0 commit comments