class Solution(object):
def uniquePaths(self, m, n):
"""
:type m: int
:type n: int
:rtype: int
dp=[[1]*n for x in range(m)]
for i in range(1,m):
for j in range(1,n):
dp[i][j]=dp[i-1][j]+dp[i][j-1]
return dp[-1][-1]
"""
dp=[1]*m
for j in range(1,n):
for i in range(1,m):
dp[i]+=dp[i-1]
return dp[-1]
方法一:
和算最小和一样,先算行0和列0,相加
方法二:
先直接算向下走,走列次,一直摆到最后一个