92. Leetcode 63. 不同路径 II (动态规划-路径规划)
步骤一、确定状态:
确定dp数组及含义 dp[i][j]表示从左上角到第i行j列这个位置的路径条数
步骤二、推断状态方程
dp[i][j] = dp[i-1][j] + dp[i][j-1]
步骤三、规定初始条件:
初始条件:
dp = [[0 for _ in range(n)] for _ in range(m)]
步骤四、计算顺序:
从(1,1)位置开始 i从1到m-1遍历 j从1到n-1遍历
class Solution:
def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:
m, n = len(obstacleGrid), len(obstacleGrid[0])
dp = [[0 for _ in range(n)] for _ in range(m)]
for i in range(m):
if obstacleGrid[i][0
共有 0 条评论