Unique Paths II
Thoughts
Code
class Solution {
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
int n = obstacleGrid[0].length;
int[] f = new int[n];
f[0] = 1;
for (int[] row : obstacleGrid) {
for (int j = 0; j < n; j++) {
if (row[j] == 1) {
f[j] = 0;
} else if (j > 0) {
f[j] += f[j - 1];
}
}
}
return f[n - 1];
}
}Analysis
Last updated