File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-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+ # 0์ด ์๋ ํ, ์ด์ ๊ธฐ๋กํด๋๊ณ ๊ทธ ๊ธฐ๋ก์ ํ ๋๋ก ๋ฐ๊พธ๊ธฐ(์๊ฐ๋ณต์ก๋ O(m*n), ๊ณต๊ฐ๋ณต์ก๋ O(m+n))
7+ m , n = len (matrix ), len (matrix [0 ])
8+ # rows, cols = [] , [] -> ์ค๋ณต๋์ด ๋ค์ด๊ฐ ์ ์์. ๋ถํ์ํจ. ์ค๋ณต์ ๊ฑฐ๋ฅผ ์ํด set ์ฌ์ฉ.
9+ rows , cols = set (), set ()
10+
11+ # 0์ด ์๋ ํ, ์ด ๊ธฐ๋ก
12+ for i in range (m ):
13+ for j in range (n ):
14+ if matrix [i ][j ] == 0 :
15+ rows .add (i )
16+ cols .add (j )
17+
18+ # ๊ธฐ๋ก๋ ํ 0์ผ๋ก ๋ฐ๊พธ๊ธฐ
19+ for i in rows :
20+ for j in range (n ):
21+ matrix [i ][j ] = 0
22+
23+ # ๊ธฐ๋ก๋ ์ด 0์ผ๋ก ๋ฐ๊พธ๊ธฐ
24+ for j in cols :
25+ for i in range (m ):
26+ matrix [i ][j ] = 0
You canโt perform that action at this time.
0 commit comments