We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9b02d1b commit 5893eafCopy full SHA for 5893eaf
tree/113_pathSum.py
@@ -46,6 +46,20 @@ def helper(root, total):
46
helper(root, total)
47
return ans
48
49
+ def pathSum_dfs_2(self, root: TreeNode, total: int) -> List[List[int]]:
50
+ def dfs(root, tmp, total):
51
+ if not root:
52
+ return
53
+ if not root.left and not root.right and root.val == total:
54
+ tmp += [root.val]
55
+ ans.append(tmp)
56
+ dfs(root.left, tmp + [root.val], total - root.val)
57
+ dfs(root.right, tmp + [root.val], total - root.val)
58
+
59
+ ans = []
60
+ dfs(root, [], total)
61
+ return ans
62
63
64
if __name__ == '__main__':
65
lst = [1, 2, 3]
0 commit comments