Merge pull request #497 from smartAndgoodMark/patch-1

Update Leetcode 题解.md
This commit is contained in:
郑永川 2018-12-17 18:25:13 +08:00 committed by GitHub
commit 4b35ec32a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2552,13 +2552,21 @@ public int minPathSum(int[][] grid) {
for(int i =0;i<m;i++) { for(int i =0;i<m;i++) {
for(int j=0;j<n;j++){ for(int j=0;j<n;j++){
if(i==0) { if(i==0) {
dp[j] = dp[j - 1]; if(j==0) {
} else { dp[j] = grid[i][j];
dp[j] = Math.min(dp[j - 1], dp[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]; return dp[n-1];
} }
``` ```