From f8392906ac8463504e2707f3762e3fc39f909782 Mon Sep 17 00:00:00 2001 From: SianXiaoCHN Date: Fri, 25 Mar 2022 20:25:06 -0500 Subject: [PATCH] =?UTF-8?q?0112.=E8=B7=AF=E5=BE=84=E6=80=BB=E5=92=8C=20pyt?= =?UTF-8?q?hon=20=E7=B2=BE=E7=AE=80=E9=80=92=E5=BD=92=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 0112.路径总和 python 精简113递归返回条件 --- problems/0112.路径总和.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/problems/0112.路径总和.md b/problems/0112.路径总和.md index 03ec1bb7..ff682739 100644 --- a/problems/0112.路径总和.md +++ b/problems/0112.路径总和.md @@ -496,11 +496,10 @@ class solution: def pathsum(self, root: treenode, targetsum: int) -> list[list[int]]: def traversal(cur_node, remain): - if not cur_node.left and not cur_node.right and remain == 0: - result.append(path[:]) - return - - if not cur_node.left and not cur_node.right: return + if not cur_node.left and not cur_node.right: + if remain == 0: + result.append(path[:]) + return if cur_node.left: path.append(cur_node.left.val)