Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e1e7b1

Browse files
authored
Create 73-Set-Matrix-Zeroes.js
1 parent 0e5bd33 commit 6e1e7b1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

javascript/73-Set-Matrix-Zeroes.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @param {number[][]} matrix
3+
* @return {void} Do not return anything, modify matrix in-place instead.
4+
*/
5+
var setZeroes = function(matrix) {
6+
let row = new Array(matrix.length);
7+
let col = new Array(matrix[0].length);
8+
9+
for (let i = 0; i < row.length; i++) {
10+
for (let j = 0; j < col.length; j++) {
11+
if (matrix[i][j] === 0) {
12+
row[i] = 0;
13+
col[j] = 0;
14+
}
15+
}
16+
}
17+
18+
for (let i = 0; i < row.length; i++) {
19+
for (let j = 0; j < col.length; j++) {
20+
if (row[i] == 0 || col[j] == 0) {
21+
matrix[i][j] = 0;
22+
}
23+
}
24+
}
25+
26+
};

0 commit comments

Comments
 (0)