Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions bangdori/Set Matrix Zeroes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @param {number[][]} matrix
* @return {void} Do not return anything, modify matrix in-place instead.
*/
var setZeroes = function (matrix) {
const rowSize = matrix.length;
const colSize = matrix[0].length;

const zeroRows = new Set();
const zeroCols = new Set();

for (let row = 0; row < rowSize; row++) {
for (let col = 0; col < colSize; col++) {
if (matrix[row][col] !== 0) continue;

zeroRows.add(row);
zeroCols.add(col);
}
}
Comment on lines +12 to +19
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 if (matrix[row][col] === 0){
      zeroRows.add(row);
      zeroCols.add(col);
}

로 안하고 !==으로 표현한건 가독성 때문인건가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 맞습니다

해당 문제에서 0인 지점에 대해서만, 해당 지점을 기준으로 행과 열을 0으로 초기화하라고 했기 때문에 0이 아닌 경우를 무시하도록 하였습니다.


for (const row of zeroRows) {
for (let col = 0; col < colSize; col++) {
matrix[row][col] = 0;
}
}

for (const col of zeroCols) {
for (let row = 0; row < rowSize; row++) {
matrix[row][col] = 0;
}
}
};
Loading