From 497812bd4232da65e88b9e7628a0e7de5abb3030 Mon Sep 17 00:00:00 2001 From: Yutong Wang Date: Mon, 17 Sep 2018 23:40:06 -0700 Subject: [PATCH] Fix a bug in the Minimum Path Sum solution Check boundary --- notes/Leetcode 题解.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notes/Leetcode 题解.md b/notes/Leetcode 题解.md index 2d6b2d5f..d09ff18d 100644 --- a/notes/Leetcode 题解.md +++ b/notes/Leetcode 题解.md @@ -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]; }