auto commit
This commit is contained in:
parent
4b35ec32a3
commit
76ad497f7d
|
@ -2551,22 +2551,16 @@ public int minPathSum(int[][] grid) {
|
|||
int[] dp = new int[n];
|
||||
for (int i = 0; i < m; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
if(i==0) {
|
||||
if (j == 0) {
|
||||
dp[j] = grid[i][j];
|
||||
dp[j] = dp[j]; // 只能从上侧走到该位置
|
||||
} else if (i == 0) {
|
||||
dp[j] = dp[j - 1]; // 只能从左侧走到该位置
|
||||
} else {
|
||||
dp[j] = Math.min(dp[j - 1], dp[j]);
|
||||
}
|
||||
else {
|
||||
dp[j]=dp[j-1] + grid[i][j];
|
||||
}
|
||||
}else if(j==0) {
|
||||
dp[j] = dp[j] + grid[i][j];
|
||||
}
|
||||
else{
|
||||
dp[j] = Math.min(dp[j],dp[j-1])+grid[i][j];
|
||||
dp[j] += grid[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dp[n - 1];
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue
Block a user