Skip to content

Conversation

@jungmyunggi
Copy link
Collaborator

문제

Type Info
Time Complexity O(N*M)
Space Complexity O(N*M)
Algorithm 브루트포스
Data Structure Array

Constraints

  • m == matrix.length
  • n == matrix[0].length
  • 1 <= m, n <= 200
  • -231 <= matrix[i][j] <= 231 - 1

Edge Case

x

풀이

var setZeroes = function(matrix) {
    if(행렬의 행이 1개이고 0을 포함하는 경우){
        return 해당 행을 0으로 초기화 시킨 행렬
    }
    const arr = []
    for(행의 개수만큼 반복){
        for (열의 개수만큼 반복){
            if(행렬의 해당 요소가 0이라면){
                arr에 [행,열] 저장
            }
        }
};
for(arr길이만큼 반복){
    for(열의 개수만큼 반복){
        arr에 저장된 열 0으로 초기화
    }
    for(행의 개수만큼 반복){
        arr에 저장된 행 0으로 초기화
    }

return matrix
}

어려웠던 점

  • 초기에 matrix행렬을 하나 더 복사해서 탐색 후 0 요소를 찾으면 원본 행렬의 값을 바꾸는 식으로 작성 했는데 쓸데없이 공간을 낭비한다고 생각이 되어서 요소가 0인 위치만 기억해둔 다음 반복문을 돌려서 행,열 모두 0으로 초기화 시켜주었다.

알게된 점

x

@jungmyunggi jungmyunggi self-assigned this Jan 2, 2025
@github-actions github-actions bot merged commit d25b8bc into main Jan 10, 2025
2 checks passed
@BangDori BangDori deleted the jungmyunggi/set-matrix-zeroes branch January 10, 2025 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants