File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ Constraints:
3+ - m == matrix.length
4+ - n == matrix[0].length
5+ - 1 <= m, n <= 200
6+ - -2^31 <= matrix[i][j] <= 2^31 - 1
7+
8+ Time Complexity: O(m*n)
9+ - m์ ํ, n์ ์ด์ ์๋ฏธ
10+ - 0 ์ฐพ๊ธฐ - O(m*n)
11+ - ํ๊ณผ ์ด ๋ณํ - O(m*n)
12+
13+ Space Complexity: O(m*n)
14+ - zeros ๋ฐฐ์ด์ด ์ต๋ m*n ํฌ๊ธฐ๊น์ง ์ ์ฅ ๊ฐ๋ฅ
15+
16+ ํ์ด ๋ฐฉ๋ฒ:
17+ 1. 0 ์์น ์ ์ฅ
18+ 2. ์ ์ฅ๋ 0์ ํ๊ณผ ์ด์ ๋ชจ๋ 0์ผ๋ก ๋ณํ
19+ 3. ์ฃผ์์ - ํ๋ ฌ ๊ฐ ํ์๊ณผ ๋ณ๊ฒฝ์ ๋์์ ์ํํ๋ฉด ์๋ ์ด๋ค ๊ฐ์ด 0์ด์๋์ง ๊ตฌ๋ถํ๊ธฐ ์ด๋ ค์์ง
20+ """
21+
22+ class Solution :
23+ def setZeroes (self , matrix : List [List [int ]]) -> None :
24+ """
25+ Do not return anything, modify matrix in-place instead.
26+ """
27+ zeros = []
28+
29+ for r in range (len (matrix )):
30+ for c in range (len (matrix [0 ])):
31+ if matrix [r ][c ] == 0 :
32+ zeros .append ((r , c ))
33+
34+ for r , c in zeros :
35+ for i in range (len (matrix [0 ])):
36+ matrix [r ][i ] = 0
37+ for i in range (len (matrix )):
38+ matrix [i ][c ] = 0
You canโt perform that action at this time.
0 commit comments