未验证 提交 497812bd 编写于 作者: Y Yutong Wang 提交者: GitHub

Fix a bug in the Minimum Path Sum solution

Check boundary
上级 e3c63b66
......@@ -2505,9 +2505,9 @@ 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];
if (j>0) dp[j] = dp[j - 1];
} else {
dp[j] = Math.min(dp[j - 1], dp[j]);
if (j>0) dp[j] = Math.min(dp[j - 1], dp[j]);
}
dp[j] += grid[i][j];
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册