feat: 2025-10-31打卡
This commit is contained in:
34
63.unique-paths-ii.java
Normal file
34
63.unique-paths-ii.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* @lc app=leetcode id=63 lang=java
|
||||
*
|
||||
* [63] Unique Paths II
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
class Solution {
|
||||
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
|
||||
int[][] dp = new int[obstacleGrid.length][obstacleGrid[0].length];
|
||||
for(int i=0;i<dp.length;i++) {
|
||||
for(int j=0;j<dp[0].length;j++) {
|
||||
dp[i][j] = 0;
|
||||
}
|
||||
}
|
||||
dp[0][0] = obstacleGrid[0][0]==1?0:1;
|
||||
for(int i = 0; i<dp.length; i++) {
|
||||
for(int j=0; j<dp[0].length; j++) {
|
||||
if(obstacleGrid[i][j] == 1) {
|
||||
continue;
|
||||
}
|
||||
if(i-1>=0) {
|
||||
dp[i][j] += dp[i-1][j];
|
||||
}
|
||||
if(j-1>=0) {
|
||||
dp[i][j] += dp[i][j-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return dp[dp.length-1][dp[0].length-1];
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
Reference in New Issue
Block a user