Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 815 Bytes

63. Unique Paths II.md

File metadata and controls

36 lines (24 loc) · 815 Bytes

Leetcode

63. Unique Paths II

문제링크

코드

class Solution {
    func uniquePathsWithObstacles(_ obstacleGrid: [[Int]]) -> Int {
        var matrix: [[Int]] = Array(repeating: Array(repeating: 0, count: obstacleGrid[0].count), count: obstacleGrid.count)
        
        matrix[0][0] = 1
        for i in 0..<obstacleGrid.count {
            for j in 0..<obstacleGrid[0].count {
                if i > 0 { matrix[i][j] += matrix[i - 1][j] }
                if j > 0 { matrix[i][j] += matrix[i][j - 1] }
                if obstacleGrid[i][j] == 1 { matrix[i][j] = 0 }
            }
        }
        
        return matrix[obstacleGrid.count - 1][obstacleGrid[0].count - 1]
    }
    
}

풀이 이유

참고한 내용