mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
@ -176,16 +176,14 @@ class Solution {
|
||||
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
|
||||
int n = obstacleGrid.length, m = obstacleGrid[0].length;
|
||||
int[][] dp = new int[n][m];
|
||||
dp[0][0] = 1 - obstacleGrid[0][0];
|
||||
for (int i = 1; i < m; i++) {
|
||||
if (obstacleGrid[0][i] == 0 && dp[0][i - 1] == 1) {
|
||||
dp[0][i] = 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < m; i++) {
|
||||
if (obstacleGrid[0][i] == 1) break; //一旦遇到障碍,后续都到不了
|
||||
dp[0][i] = 1;
|
||||
}
|
||||
for (int i = 1; i < n; i++) {
|
||||
if (obstacleGrid[i][0] == 0 && dp[i - 1][0] == 1) {
|
||||
dp[i][0] = 1;
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (obstacleGrid[i][0] == 1) break; ////一旦遇到障碍,后续都到不了
|
||||
dp[i][0] = 1;
|
||||
}
|
||||
for (int i = 1; i < n; i++) {
|
||||
for (int j = 1; j < m; j++) {
|
||||
|
Reference in New Issue
Block a user