题解 | #二叉树中和为某一值的路径(二)#
二叉树中和为某一值的路径(二)
https://www.nowcoder.com/practice/b736e784e3e34731af99065031301bca
class Solution: def FindPath(self, root: TreeNode, target: int) -> List[List[int]]: def dfs(root, target,tmp): if not root: return [] if root.left: dfs(root.left, target-root.val, tmp+[root.val]) if root.right: dfs(root.right, target-root.val, tmp+[root.val]) if target == root.val and not root.left and not root.right: tmp += [root.val] res.append(tmp) res = [] tmp = [] dfs(root,target,[]) return res