# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]:
        res = []
        path = []
        def find_path(root, target):
            if not root: return []
            path.append(root.val)
            target -= root.val
            if target == 0 and root.left is None and root.right is None:
                res.append(path[::])
            
            find_path(root.left, target)
            find_path(root.right, target)
            path.pop()
        find_path(root, sum)
        return res

相关文章:

  • 2021-06-04
  • 2021-11-20
猜你喜欢
  • 2022-01-03
  • 2021-09-08
  • 2021-10-04
  • 2021-06-05
  • 2021-12-14
相关资源
相似解决方案