File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * ์ฃผ์ด์ง ๊ฒฉ์์์ ์์๊ฐ 0์ธ ํ๊ณผ ์ด์ ๊ฐ์ 0์ผ๋ก ์์ ํ๋ ํจ์
3
+ * @param {number[][] } matrix
4
+ * @return {void } Do not return anything, modify matrix in-place instead.
5
+ */
6
+ const setZeroes = function ( matrix ) {
7
+ const m = matrix . length ;
8
+ const n = matrix [ 0 ] . length ;
9
+ const rows = new Set ( ) ;
10
+ const cols = new Set ( ) ;
11
+
12
+ for ( let r = 0 ; r < m ; r ++ ) {
13
+ for ( let c = 0 ; c < n ; c ++ ) {
14
+ if ( matrix [ r ] [ c ] === 0 ) {
15
+ rows . add ( r ) ;
16
+ cols . add ( c ) ;
17
+ }
18
+ }
19
+ }
20
+
21
+ rows . forEach ( ( row ) => matrix [ row ] = Array ( n ) . fill ( 0 ) ) ;
22
+ cols . forEach ( ( col ) => {
23
+ for ( let r = 0 ; r < m ; r ++ ) {
24
+ matrix [ r ] [ col ] = 0 ;
25
+ }
26
+ } ) ;
27
+ } ;
28
+
29
+ // ์๊ฐ๋ณต์ก๋: O(m * n)
30
+ // ๊ณต๊ฐ๋ณต์ก๋: O(m + n)
You canโt perform that action at this time.
0 commit comments