-
Notifications
You must be signed in to change notification settings - Fork 481
/
Copy path0063.cpp
38 lines (35 loc) · 908 Bytes
/
0063.cpp
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
#include <iostream>
#include <vector>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid)
{
int m = obstacleGrid.size();
int n = obstacleGrid[0].size();
vector<vector<int>> mem(m, vector<int>(n, 0));
mem[0][0] = 1;
for (unsigned int i = 0; i < m; ++i)
{
for (unsigned int j = 0; j < n; ++j)
{
if (obstacleGrid[i][j] == 0)
{
if (j) mem[i][j] += mem[i][j - 1];
if (i) mem[i][j] += mem[i - 1][j];
}
else
{
mem[i][j] = 0;
}
}
}
return mem[m - 1][n - 1];
}
};
int main()
{
return 0;
}