[Leetcode - Medium] Set Matrix Zeroes#40
Merged
github-actions[bot] merged 1 commit intomainfrom Jan 9, 2025
Merged
Conversation
jungmyunggi
reviewed
Jan 2, 2025
Comment on lines
+12
to
+19
| 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); | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
if (matrix[row][col] === 0){
zeroRows.add(row);
zeroCols.add(col);
}
로 안하고 !==으로 표현한건 가독성 때문인건가요?
Member
Author
There was a problem hiding this comment.
넵 맞습니다
해당 문제에서 0인 지점에 대해서만, 해당 지점을 기준으로 행과 열을 0으로 초기화하라고 했기 때문에 0이 아닌 경우를 무시하도록 하였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
문제
Constraints
m == matrix.lengthn == matrix[0].length1 <= m, n <= 200-231 <= matrix[i][j] <= 231 - 1Edge Case
풀이
row,col을 각각 따로zeroRows,zeroColsset에 저장한다.zeroRows집합을 순회하면서zeroRow에 해당하는 모든col에 대해 0으로 수정한다.zeroCols집합을 순회하면서zeroCol에 해당하는 모든row에 대해 0으로 수정한다.어려웠던 점
DFS로 문제 풀이 방법을 정하고 문제 풀이를 시도해보니 코드가 어느정도 완성된 상태에서 반례 케이스에 대한 대응이 어려웠다.
알게된 점