Tap here to switch tabs
Problem
Submissions

Problem: Sum Root to Leaf Numbers

med
30 min
Try to solve the Sum Root to Leaf Numbers problem.

Statement

Given the root node root of a binary tree where each node contains a single digit, treat every root to leaf path as a base 1010 number formed by concatenating the digits along that path from root to leaf.

Return the sum of all such numbers across every root to leaf path in the tree.

A leaf is a node with no children.

Constraints:

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

  • 00 \leq Node.val 9\leq 9

  • The depth of the tree will not exceed 1010

Tap here to switch tabs
Problem
Submissions

Problem: Sum Root to Leaf Numbers

med
30 min
Try to solve the Sum Root to Leaf Numbers problem.

Statement

Given the root node root of a binary tree where each node contains a single digit, treat every root to leaf path as a base 1010 number formed by concatenating the digits along that path from root to leaf.

Return the sum of all such numbers across every root to leaf path in the tree.

A leaf is a node with no children.

Constraints:

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

  • 00 \leq Node.val 9\leq 9

  • The depth of the tree will not exceed 1010