Sum Root to Leaf Numbers
Given a binary tree containing digits from0-9
only, each root-to-leaf path could represent a number.
An example is the root-to-leaf path1->2->3
which represents the number123
.
Find the total sum of all root-to-leaf numbers.
Note: A leaf is a node with no children.
Example
Example 1:
Example 2:
Note
Divide and conquer
num是递归传递的参数
num = num * 10 + root.val
一直到叶子结点
Code
Last updated