Merge pull request #497 from smartAndgoodMark/patch-1
Update Leetcode 题解.md
This commit is contained in:
commit
4b35ec32a3
|
@ -2552,13 +2552,21 @@ public int minPathSum(int[][] grid) {
|
|||
for(int i =0;i<m;i++) {
|
||||
for(int j=0;j<n;j++){
|
||||
if(i==0) {
|
||||
dp[j] = dp[j - 1];
|
||||
} else {
|
||||
dp[j] = Math.min(dp[j - 1], dp[j]);
|
||||
if(j==0) {
|
||||
dp[j] = grid[i][j];
|
||||
}
|
||||
dp[j] += grid[i][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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dp[n-1];
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue
Block a user