๐ 63. ไธๅ่ทฏๅพ II
2022ๅนด6ๆ9ๆฅๅฐไบ 1 ๅ้
๐ 63. ไธๅ่ทฏๅพ II
้พๅบฆ: ๐
้ฎ้ขๆ่ฟฐ
่งฃๆณ
class Solution {
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
// ๆ่ทฏ๏ผ
// dp[i][j] = dp[i - 1][j] + dp[i][j - 1], 0
int row = obstacleGrid.length;
int col = obstacleGrid[0].length;
int[][] dp = new int[row][col];
for(int i = 0; i < row; i ++) {
if(obstacleGrid[i][0] != 1) {
dp[i][0] = 1;
} else {
break;
}
}
for(int j = 0; j < col; j ++) {
if(obstacleGrid[0][j] != 1) {
dp[0][j] = 1;
} else {
break;
}
}
for(int i = 1; i < row; i ++) {
for(int j = 1; j < col; j ++) {
if(obstacleGrid[i][j] != 1) {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
}
return dp[row - 1][col - 1];
}
}