问题描述 用动态规划做的,注意最左边和最上边的情况
设置从0到n-1的列表可以用list(range(n))
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
dp = [1]*m
for i in range(1,n):
for j in range(1,m):
dp[j]+=dp[j-1]
return dp[m-1]
运行结果: