-
Notifications
You must be signed in to change notification settings - Fork 481
/
0063.cpp
31 lines (30 loc) · 851 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
#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>>& data)
{
if (data.empty()) return 0;
int m = data.size(), n = data[0].size();
vector<vector<unsigned int>> mem(m, vector<unsigned int>(n, 0));
for (int i = 0; i < m; ++i)
{
for (int j = 0; j < n; ++j)
{
if (data[i][j] == 1) continue;
if (i > 0 and j > 0) mem[i][j] = mem[i-1][j] + mem[i][j-1];
else if (i) mem[i][j] = mem[i-1][j];
else if (j) mem[i][j] = mem[i][j-1];
else mem[i][j] = 1;
}
}
return mem[m-1][n-1];
}
};
int main()
{
return 0;
}