Tap here to switch tabs
Problem
Submissions

Problem: Sum of Root To Leaf Binary Numbers

Try to solve the Sum of Root To Leaf Binary Numbers problem.

Statement

You are given the root of a binary tree where each node holds a value of either 00 or 11.

Each path from the root to a leaf node represents a binary number starting with the most significant bit at the root. For example, a path containing values 1o0o11 o 0 o 1 represents the binary number 1012101_2, which is equivalent to 55 in base 1010.

Return the total sum of all binary numbers formed by paths from the root to every leaf node.

Constraints:

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

  • Node.val is either 00 or 11.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sum of Root To Leaf Binary Numbers

Try to solve the Sum of Root To Leaf Binary Numbers problem.

Statement

You are given the root of a binary tree where each node holds a value of either 00 or 11.

Each path from the root to a leaf node represents a binary number starting with the most significant bit at the root. For example, a path containing values 1o0o11 o 0 o 1 represents the binary number 1012101_2, which is equivalent to 55 in base 1010.

Return the total sum of all binary numbers formed by paths from the root to every leaf node.

Constraints:

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

  • Node.val is either 00 or 11.