From 430e1e7eae1eeab7e3b516b2385657e51993250c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=AB=E7=A3=8A=26Mark?= <1819172399@qq.com> Date: Sun, 16 Dec 2018 21:09:03 +0800 Subject: [PATCH] =?UTF-8?q?Update=20Leetcode=20=E9=A2=98=E8=A7=A3.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改矩阵路径代码错误,难以置信这么多人star的项目有这种错误 --- notes/Leetcode 题解.md | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/notes/Leetcode 题解.md b/notes/Leetcode 题解.md index cfa4a59f..281bae0a 100644 --- a/notes/Leetcode 题解.md +++ b/notes/Leetcode 题解.md @@ -2544,23 +2544,31 @@ Given the above grid map, return 7. Because the path 1→3→1→1→1 minimizes ```java public int minPathSum(int[][] grid) { - if (grid.length == 0 || grid[0].length == 0) { - return 0; - } - int m = grid.length, n = grid[0].length; - int[] dp = new int[n]; - for (int i = 0; i < m; i++) { - for (int j = 0; j < n; j++) { - if (i == 0) { - dp[j] = dp[j - 1]; - } else { - dp[j] = Math.min(dp[j - 1], dp[j]); - } - dp[j] += grid[i][j]; + if (grid.length==0 || grid[0].length == 0) { + return 0; } + int m = grid.length, n = grid[0].length; + int[] dp = new int[n]; + for(int i =0;i