Path Sum II

Given the root of a binary tree and an integer targetSum, find all root-to-leaf paths where the sum of the node values equals targetSum. The solution should be in the form of lists of node values.

Constraints

  • The number of nodes in the tree is in the range [0, 5000].
  • -1000 <= Node.val <= 1000
  • -1000 <= targetSum <= 1000
Saving… · 11 lines
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right

class Solution:
def pathSum(self, root: TreeNode, targetSum: int) -> List[List[int]]:


Console

Click Run to execute sample tests.