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
+ * @param {number[][] } matrix
3
+ * @return {void } Do not return anything, modify matrix in-place instead.
4
+ */
5
+ var setZeroes = function ( matrix ) {
6
+ const coord = [ ] ;
7
+
8
+ for ( let i = 0 ; i < matrix . length ; i ++ ) {
9
+ for ( let j = 0 ; j < matrix [ i ] . length ; j ++ ) {
10
+
11
+ const num = matrix [ i ] [ j ] ;
12
+
13
+ if ( num === 0 ) {
14
+ coord . push ( { y : i , x : j } ) ;
15
+ }
16
+ }
17
+ }
18
+
19
+ for ( let k = 0 ; k < coord . length ; k ++ ) {
20
+ const { y } = coord [ k ] ;
21
+
22
+ for ( let j = 0 ; j < matrix [ 0 ] . length ; j ++ ) {
23
+ matrix [ y ] [ j ] = 0 ;
24
+ }
25
+ }
26
+
27
+ for ( let l = 0 ; l < coord . length ; l ++ ) {
28
+ const { x } = coord [ l ] ;
29
+
30
+ for ( let j = 0 ; j < matrix . length ; j ++ ) {
31
+ matrix [ j ] [ x ] = 0 ;
32
+ }
33
+ }
34
+ } ;
35
+
36
+ // 시간복잡도 O(n * m)
37
+ // 공간복잡도 O(n * m)
38
+
You can’t perform that action at this time.
0 commit comments