题目:
思路:
在原先排列组合的基础上,将有障碍的路线去除。
代码:
class Solution(object): def uniquePathsWithObstacles(self, obstacleGrid): """ :type obstacleGrid: List[List[int]] :rtype: int """ m=len(obstacleGrid[0]) n=len(obstacleGrid) tmp=[[0]*m]*n for i in range(n): for j in range(m): if obstacleGrid[i][j]==1: tmp[i][j]=0 else: if i==0 and j==0: tmp[i][j]=1 elif i==0: tmp[i][j]=tmp[i][j-1] elif j==0: tmp[i][j]=tmp[i-1][j] else: tmp[i][j]=tmp[i-1][j]+tmp[i][j-1] return tmp[n-1][m-1]
