mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-24 09:02:25 +08:00
0112.路径总和 python 精简递归返回条件
0112.路径总和 python 精简113递归返回条件
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user