Unique Paths II
[
[0,0,0],
[0,1,0],
[0,0,0]
]class Solution {
public int uniquePathsWithObstacles(int[][] board) {
if(board == null || board.length == 0 || board[0] == null || board[0].length == 0)
return 0;
int n = board.length;
int m = board[0].length;
int[][] f= new int[n + 1][m + 1];
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
if(i == 1 && j == 1)
f[1][1] = board[i - 1][j - 1] == 0 ? 1 : 0;
else
f[i][j] = board[i - 1][j - 1] == 0 ? f[i-1][j] + f[i][j - 1] : 0;
}
}
return f[n][m];
}
}Last updated