From 3dad0a822d4aa688af9ea9da05f5a9ab9db0421a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BD=A9=E8=BE=95=E9=BE=99=E5=84=BF?= Date: Sat, 5 Feb 2022 22:28:04 +0800 Subject: [PATCH] =?UTF-8?q?1219:=E9=BB=84=E9=87=91=E7=9F=BF=E5=B7=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/leetcode/editor/cn/PathWithMaximumGold.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/leetcode/editor/cn/PathWithMaximumGold.java b/src/main/java/leetcode/editor/cn/PathWithMaximumGold.java index 09f4bd8..71ab122 100644 --- a/src/main/java/leetcode/editor/cn/PathWithMaximumGold.java +++ b/src/main/java/leetcode/editor/cn/PathWithMaximumGold.java @@ -68,9 +68,11 @@ class PathWithMaximumGold { boolean[][] use = new boolean[grid.length][grid[0].length]; for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[0].length; j++) { - use[i][j] = true; - counts = Math.max(counts, dfs(i, j, grid, use)); - use[i][j] = false; + if (grid[i][j] != 0) { + use[i][j] = true; + counts = Math.max(counts, dfs(i, j, grid, use)); + use[i][j] = false; + } } } return counts;