From a81537b19d25e78e692cd6916d599452a6071109 Mon Sep 17 00:00:00 2001 From: LazyTraveller13 <55097178+LazyTraveller13@users.noreply.github.com> Date: Tue, 24 Mar 2020 15:38:25 -0400 Subject: [PATCH] =?UTF-8?q?leetcode=2064=20=E7=9F=A9=E9=98=B5=E7=9A=84?= =?UTF-8?q?=E6=9C=80=E5=B0=8F=E8=B7=AF=E5=BE=84=E5=92=8C=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如果j == 0的时候会产生ArrayOutOfBoundException,所以应该加上j != 0的判断条件 --- "notes/Leetcode \351\242\230\350\247\243.md" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/notes/Leetcode \351\242\230\350\247\243.md" "b/notes/Leetcode \351\242\230\350\247\243.md" index bdf03c8..7358ece 100644 --- "a/notes/Leetcode \351\242\230\350\247\243.md" +++ "b/notes/Leetcode \351\242\230\350\247\243.md" @@ -2504,9 +2504,9 @@ 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 (i == 0 && j != 0) { dp[j] = dp[j - 1]; - } else { + } else if (j != 0) { dp[j] = Math.min(dp[j - 1], dp[j]); } dp[j] += grid[i][j];