class Solution:
def uniquePaths(self, m: int, n: int) -> int:
dp = [[1] * n for _ in range(m)]
for i in range(1, m):
for j in range(1, n):
# Calculate the number of unique paths for cell (i, j)
dp[i][j] = dp[i-1][j] + dp[i][j-1]
return dp[m-1][n-1]
# if not m or not n:
# return 0
# grid = [[0] * n for _ in range(m)]
# grid[0][0] = 1
# directions = [(1, 0), (0, 1)]
# queue = deque([(0, 0)])
# while queue:
# x, y = queue.popleft()
# for dx, dy in directions:
# new_x, new_y = x + dx, y + dy
# if 0 <= new_x < m and 0 <= new_y < n:
# grid[new_x][new_y] += grid[x][y]
# queue.append((new_x, new_y))
# return grid[m - 1][n - 1]
'LEETCODE' 카테고리의 다른 글
up_stage interview prep (0) | 2023.11.10 |
---|---|
#54. Spiral Matrix (0) | 2023.11.01 |
#55. Jump Game (0) | 2023.11.01 |
#53. Maximum Subarray (0) | 2023.11.01 |
#34. Find First and Last Position of Element in Sorted Array (0) | 2023.11.01 |