auto commit

This commit is contained in:
CyC2018 2018-12-17 18:27:21 +08:00
parent 4b35ec32a3
commit 76ad497f7d

View File

@ -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];
}
```