-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniquePathII.java
More file actions
29 lines (25 loc) · 881 Bytes
/
UniquePathII.java
File metadata and controls
29 lines (25 loc) · 881 Bytes
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
public class UniquePathII {
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
if(obstacleGrid == null || obstacleGrid.length ==0) return 0;
int m=obstacleGrid.length;
int n = obstacleGrid[0].length;
int[] count = new int[n];
for(int i=0; i<m; i++) {
for(int j=0; j<n; j++) {
if(obstacleGrid[i][j] == 1)
count[j] = 0;
else {
if(j == 0 && i == 0)
count[j] = 1;
else if (j==0)
count[j] = count[j];
else if (i==0)
count[j] = count[j-1];
else
count[j] = count[j-1] + count[j];
}
}
}
return count[n-1];
}
}