-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
33 lines (30 loc) · 889 Bytes
/
Solution.java
File metadata and controls
33 lines (30 loc) · 889 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
30
31
32
33
package leetCode_63;
/**
* @author dimdark
* @date 2017-09-27
* @time 4:31 PM
*/
public class Solution {
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
int n = obstacleGrid.length, m = obstacleGrid[0].length;
int[] dp = new int[m];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (obstacleGrid[i][j] != 1) {
if (i != 0 && j != 0) {
dp[j] += dp[j - 1];
} else if (i == 0 && j != 0) {
dp[j] = dp[j - 1];
} else if (i != 0 && j == 0) {
dp[j] = dp[j];
} else {
dp[j] = 1;
}
} else {
dp[j] = 0;
}
}
}
return dp[m - 1];
}
}