classSolution(object):defuniquePaths(self, m, n):"""
:type m: int
:type n: int
:rtype: int
"""
dp=[[0]*m for i inrange(n)]for i inrange(m):
dp[0][i]=1for j inrange(n):
dp[j][0]=1for i inrange(1,n):for j inrange(1,m):
dp[i][j]= dp[i-1][j]+ dp[i][j-1]return dp[n-1][m-1]
63. Unique Paths II 价格判断即可
classSolution(object):defuniquePathsWithObstacles(self, obstacleGrid):"""
:type obstacleGrid: List[List[int]]
:rtype: int
"""
m=len(obstacleGrid)if m==0:return0
n=len(obstacleGrid[0])
dp=[[0]*n for _ inrange(m)]for i inrange(m):if obstacleGrid[i][0]==0:
dp[i][0]=1else:breakfor j inrange(n):if obstacleGrid[0][j]==0:
dp[0][j]=1else:breakfor i inrange(1,m):for j inrange(1,n):if obstacleGrid[i][j]==0:
dp[i][j]=dp[i-1][j]+dp[i][j-1]return dp[m-1][n-1]