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)