Path Sum
112 Path Sum
def hasPathSum(self, root: TreeNode, sum: int) -> bool:
if not root: return False
sum -= root.val
if not root.left and not root.right and sum == 0:
return True
return self.hasPathSum(root.left, sum) or self.hasPathSum(root.right, sum)113 Path Sum II
def pathSum(self, root: TreeNode, sum: int) -> List[List[int]]:
res = []
def helper(node, s, li):
if not node: return
li.append(node.val)
s -= node.val
if not node.left and not node.right and s == 0:
res.append(li.copy())
helper(node.left, s, li)
helper(node.right, s, li)
li.pop()
helper(root, sum, [])
return res437. Path Sum III
Binary Tree Maximum Path Sum - root to any
124 Binary Tree Maximum Path Sum - any to any
Last updated