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 |