Zero to Hero
article thumbnail
Published 2021. 5. 12. 15:13
62. Unique Paths Algorithm

1. Dynamic Programming

class Solution:
    def uniquePaths(self, height: int, width: int) -> int:
        board = [[0] * width for _ in range(height)]
        for i in range(height):
            board[i][0] = 1
        for i in range(width):
            board[0][i] = 1

        for i in range(1, height):
            for j in range(1, width):
                board[i][j] = board[i - 1][j] + board[i][j - 1]
        return board[-1][-1]

예전엔 DP라고 생각도 안 났던 것 같은데 쉬운 문제지만 그래도 장족의 발전이라고 생각한다 ㅎㅎ;

'Algorithm' 카테고리의 다른 글

621. Task Scheduler  (0) 2021.05.14
114. Flatten Binary Tree to Linked List  (0) 2021.05.13
64. Minimum Path Sum  (0) 2021.05.12
199. Binary Tree Right Side View  (0) 2021.05.11
102. Binary Tree Level Order Traversal  (0) 2021.05.11
profile

Zero to Hero

@Doljae

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!