We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 0d1301a + 9e2933e commit ffb7ec8Copy full SHA for ffb7ec8
leetcode/cpp/dynamic programming/63.cpp
@@ -0,0 +1,31 @@
1
+//Unique Paths II
2
+
3
+class Solution {
4
+public:
5
+ int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
6
+ if (obstacleGrid[0][0] == 1) {
7
+ return 0;
8
+ }
9
+ int n= obstacleGrid.size();
10
+ int m= obstacleGrid[0].size();
11
+ vector<vector<int> > dp(n,vector<int> (m, 0));
12
+ int i, j;
13
+ dp[0][0]=1;
14
+ for(i=1; i<n; i++){
15
+ if(obstacleGrid[i][0]==0)
16
+ dp[i][0]=dp[i-1][0];
17
18
+ for(i=1; i<m; i++){
19
+ if(obstacleGrid[0][i]==0)
20
+ dp[0][i]=dp[0][i-1];
21
22
23
+ for(j=1; j<m; j++){
24
+ if(obstacleGrid[i][j]==0){
25
+ dp[i][j]= dp[i-1][j] + dp[i][j-1];
26
27
28
29
+ return dp[n-1][m-1];
30
31
+};
0 commit comments