【数组】63. 不同路径 II

题目:

 

 

解答:

 1 class Solution {
 2 public:
 3     int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) 
 4     {
 5         int m = obstacleGrid.size();
 6         int n = obstacleGrid[0].size();
 7         
 8         vector<vector<long long>> dp(m+1, vector<long long>(n+1));
 9 
10         dp[0][1] = 1;
11         for(int i=1; i<=m; i++)
12         {
13             for(int j=1; j<=n; j++)
14             {
15                 if(obstacleGrid[i-1][j-1])
16                 {
17                     dp[i][j] = 0;
18                 }
19                 else
20                 {
21                     dp[i][j] = dp[i-1][j] + dp[i][j-1];
22                 }
23             }
24         }
25         return dp[m][n]; 
26     }
27 };

 

posted @ 2020-05-05 15:44  梦醒潇湘  阅读(92)  评论(0)    收藏  举报