File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class Solution {
2+ public void setZeroes (int [][] matrix ) {
3+ /**
4+ 1.๋ฌธ์ : 0์ด ์กด์ฌํ๋ ์์น์ ๋ชจ๋ row, column์ 0์ผ๋ก set
5+ 2.constraints:
6+ - m,n min = 1, max = 200
7+ - space: O(mn)์ผ๋ก ํ์ดํ์ง๋ง ๊ฒ,
8+ 3.solution
9+ - 0์ ์์น๋ฅผ ํ์ธ -> 0์ ์์น๋ ์ฌ๋ฌ๊ฐ์ผ ์ ์์
10+ - row, col ๊ฐ๊ฐ 0์ ์์น ์ ์ฅ
11+ - time: O(mn), space O(m+n)
12+ */
13+ int m = matrix .length ;
14+ int n = matrix [0 ].length ;
15+ int [] row = new int [m ]; //0์ด ์กด์ฌํ๋ row ์์น์ด๋ฉด 1, ์๋๋ฉด 0
16+ int [] col = new int [n ]; //0์ด ์กด์ฌํ๋ col ์์น์ด๋ฉด 1, ์๋๋ฉด 0
17+
18+ int x = 0 ; int y = 0 ; //0์ ์์น
19+
20+ for (int i = 0 ; i < m ; i ++) {
21+ for (int j = 0 ; j < n ; j ++) {
22+ if (matrix [i ][j ] == 0 ) {
23+ row [i ] = 1 ;
24+ col [j ] = 1 ;
25+ }
26+ }
27+ }
28+
29+ for (int i = 0 ; i < m ; i ++) {
30+ for (int j = 0 ; j < n ; j ++) {
31+ if (row [i ] == 1 || col [j ] == 1 ) {
32+ matrix [i ][j ] = 0 ;
33+ }
34+ }
35+ }
36+ }
37+ }
You canโt perform that action at this time.
0 commit comments