Tap here to switch tabs
Problem
Submissions

Problem: Path Sum III

med
30 min
Try to solve the Path Sum III problem.

Statement

Given the root of a binary tree and an integer targetSum, return the number of distinct downward paths whose node values add up exactly to targetSum.

A downward path is any sequence of nodes that starts at some node and repeatedly moves to either the left child or the right child. The path does not need to start at root and does not need to end at a leaf, but it must contain at least one node.

Constraints:

  • The number of nodes in the tree is in the range [0,1000][0, 1000]

  • 109-10^9 \leq Node.val 109\leq 10^9

  • 1000-1000 \leq targetSum 1000\leq 1000

Tap here to switch tabs
Problem
Submissions

Problem: Path Sum III

med
30 min
Try to solve the Path Sum III problem.

Statement

Given the root of a binary tree and an integer targetSum, return the number of distinct downward paths whose node values add up exactly to targetSum.

A downward path is any sequence of nodes that starts at some node and repeatedly moves to either the left child or the right child. The path does not need to start at root and does not need to end at a leaf, but it must contain at least one node.

Constraints:

  • The number of nodes in the tree is in the range [0,1000][0, 1000]

  • 109-10^9 \leq Node.val 109\leq 10^9

  • 1000-1000 \leq targetSum 1000\leq 1000