-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode063_Unique_Paths_II.cpp
More file actions
55 lines (48 loc) · 1.11 KB
/
LeetCode063_Unique_Paths_II.cpp
File metadata and controls
55 lines (48 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
int m = obstacleGrid.size();
int n = obstacleGrid[0].size();
int tmp[m][n] = {0};
int i;
for(i = 0; i < m; i++)
{
if(obstacleGrid[i][0] == 1)
{
break;
}
tmp[i][0] = 1;
}
while(i < m)
{
tmp[i][0] = 0;
i++;
}
for(i = 0; i < n; i++)
{
if(obstacleGrid[0][i] == 1)
{
break;
}
tmp[0][i] = 1;
}
while(i < n)
{
tmp[0][i] = 0;
i++;
}
for(int j = 1; j < m; j++)
{
for(int k = 1; k < n; k++)
{
if(obstacleGrid[j][k] == 1)
{
tmp[j][k] = 0;
continue;
}
tmp[j][k] = tmp[j-1][k] + tmp[j][k-1];
}
}
return tmp[m-1][n-1];
}
};