File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ int uniquePathsWithObstacles (vector<vector<int >>& obstacleGrid) {
4
+ vector<vector<int >> array (obstacleGrid.size (),
5
+ vector<int >(obstacleGrid[0 ].size ()));
6
+ for (int i = 0 ; i < array.size (); i++) {
7
+ for (int j = 0 ; j < array[0 ].size (); j++) {
8
+ if (i == 0 && j == 0 ) {
9
+ if (obstacleGrid[i][j] != 1 ) {
10
+ array[i][j] = 1 ;
11
+ } else {
12
+ array[i][j] = 0 ;
13
+ }
14
+ } else if (i == 0 ) {
15
+ if (obstacleGrid[i][j] != 1 ) {
16
+ array[i][j] = array[i][j-1 ];
17
+ } else {
18
+ array[i][j] = 0 ;
19
+ }
20
+ } else if (j == 0 ) {
21
+ if (obstacleGrid[i][j] != 1 ) {
22
+ array[i][j] = array[i-1 ][j];
23
+ } else {
24
+ array[i][j] = 0 ;
25
+ }
26
+ } else if (obstacleGrid[i][j]==0 ){
27
+ array[i][j] = array[i - 1 ][j] + array[i][j - 1 ];
28
+ }else {
29
+ array[i][j]=0 ;
30
+ }
31
+ }
32
+ }
33
+ return array[array.size () - 1 ][array[0 ].size () - 1 ];
34
+ }
35
+ };
You can’t perform that action at this time.
0 commit comments