题目标题

给定H x W的数组,表示一个迷宫,0表示空格,1表示障碍,求从0, 0点到右下角最少多少步走到

难度:中级

算法
参考解析
  1. class Solution(object):
  2. def uniquePathsWithObstacles(self, obstacleGrid):
  3. r, l = len(obstacleGrid), len(obstacleGrid[0])
  4. for i in range(r):
  5. for j in range(l):
  6. if obstacleGrid[i][j] != 1:
  7. if i == 0 and j == 0:
  8. obstacleGrid[i][j] = 1
  9. elif i == 0 and j != 0:
  10. obstacleGrid[i][j] = obstacleGrid[i][j-1]
  11. elif i != 0 and j == 0:
  12. obstacleGrid[i][j] = obstacleGrid[i - 1][j]
  13. else:
  14. obstacleGrid[i][j] = obstacleGrid[i - 1][j] + obstacleGrid[i][j - 1]
  15. else:
  16. obstacleGrid[i][j] = 0
  17. return obstacleGrid[r - 1][l - 1]