Skip to content

Commit c75d8e9

Browse files
committed
set-matrix-zeroes solution
1 parent 20470c3 commit c75d8e9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

set-matrix-zeroes/jdy8739.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+

0 commit comments

Comments
 (0)