Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f22133f

Browse files
Use sets in solution 73.
1 parent 5877421 commit f22133f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

‎solutions/0073.set-matrix-zeroes.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
* @return {void} Do not return anything, modify matrix in-place instead.
44
*/
55
var setZeroes = function (matrix) {
6-
const zLines = {};
7-
const zColumns = {};
6+
const zeroRows = newSet();
7+
const zeroCols = newSet();
88

99
for (let i = 0; i < matrix.length; i++) {
1010
for (let j = 0; j < matrix[i].length; j++) {
1111
if (matrix[i][j] === 0) {
12-
zLines[i]=1;
13-
zColumns[j]=1;
12+
zeroRows.add(i);
13+
zeroCols.add(j);
1414
}
1515
}
1616
}
1717

1818
for (let i = 0; i < matrix.length; i++) {
1919
for (let j = 0; j < matrix[i].length; j++) {
20-
if (zLines[i] || zColumns[j]) {
20+
if (zeroRows.has(i) || zeroCols.has(j)) {
2121
matrix[i][j] = 0;
2222
}
2323
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /