File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ https://leetcode.com/problems/set-matrix-zeroes/description/
3+
4+ Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's.
5+ You must do it in place.
6+
7+ TC: O(m * n)
8+ SC: O(m + n), set ์๋ฃ๊ตฌ์กฐ ์ฌ์ฉ
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 = len (matrix )
17+ cols = len (matrix [0 ])
18+
19+ zero_rows = set () # ์ต๋ m๊ฐ์ ํ ์ธ๋ฑ์ค ์ ์ฅ
20+ zero_cols = set () # ์ต๋ n๊ฐ์ ์ด ์ธ๋ฑ์ค ์ ์ฅ
21+
22+ # 0์ด ์๋ ์์น ์ฐพ๊ธฐ
23+ for i in range (rows ):
24+ for j in range (cols ):
25+ if matrix [i ][j ] == 0 :
26+ zero_rows .add (i )
27+ zero_cols .add (j )
28+
29+ # 0์ด ์๋ ํ๊ณผ ์ด ๋ชจ๋ 0์ผ๋ก ๋ง๋ค๊ธฐ
30+ for i in range (rows ):
31+ for j in range (cols ):
32+ if i in zero_rows or j in zero_cols :
33+ matrix [i ][j ] = 0
You canโt perform that action at this time.
0 commit comments