← 返回 meta 的题目列表Sum Root-to-Leaf Numbers
类型:online_judge
Given a binary tree where each node contains a digit 0-9, each root-to-leaf path forms a number by concatenating digits along the path. Return the sum of all root-to-leaf numbers.
A leaf is a node with no children.
Example:
Input: [1,2,3] (root 1, left 2, right 3)
Output: 25 (numbers 12 and 13)
Constraints:
1 <= N <= 1e4
Example
Input
root=[1,2,3]
Output
25