148. Sum Root to Leaf Numbers
Medium · Binary Tree
You are given a binary tree where each node contains a single digit. Each path from the root to a leaf node represents a number formed by concatenating the digits along that path. For example, a path [1, 2, 3] represents the number 123. Your task is to find the sum of all such root-to-leaf numbers.
The input is an array representing the tree in level-order (breadth-first) format, where `null` values indicate missing nodes. Return the total sum of all root-to-leaf path numbers as an integer.
Examples
Example 1 Input: [1,2,3] Output: 25 Explanation: 12 + 13 = 25
Example 2 Input: [4,9,0,5,1] Output: 1026 Explanation: 495 + 491 + 40 = 1026
Constraints
- Standard input/output constraints apply