File tree 1 file changed +40
-0
lines changed 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .HashSet ;
2
+ import java .util .Set ;
3
+
4
+ // ์๊ฐ ๋ณต์ก๋: O(row x col)
5
+ // ๊ณต๊ฐ ๋ณต์ก๋: O(row x col)
6
+ class Solution {
7
+
8
+ public void setZeroes (int [][] matrix ) {
9
+ int row = matrix .length ;
10
+ int col = matrix [0 ].length ;
11
+
12
+ // ํ๊ณผ ์ด์ 0์ด ์๋์ง ์ฒดํฌํ ๋ฐฐ์ด
13
+ Set <Integer > rowZero = new HashSet <>();
14
+ Set <Integer > colZero = new HashSet <>();
15
+
16
+ for (int i = 0 ; i < row ; i ++) {
17
+ for (int j = 0 ; j < col ; j ++) {
18
+ if (matrix [i ][j ] == 0 ) {
19
+ rowZero .add (i );
20
+ colZero .add (j );
21
+ }
22
+ }
23
+ }
24
+
25
+ // ํ์ 0์ผ๋ก ์ค์
26
+ for (int r : rowZero ) {
27
+ for (int c = 0 ; c < col ; c ++) {
28
+ matrix [r ][c ] = 0 ;
29
+ }
30
+ }
31
+
32
+ // ์ด์ 0์ผ๋ก ์ค์
33
+ for (int c : colZero ) {
34
+ for (int r = 0 ; r < row ; r ++) {
35
+ matrix [r ][c ] = 0 ;
36
+ }
37
+ }
38
+ }
39
+ }
40
+
You canโt perform that action at this time.
0 commit comments