Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total sum of all root-to-leaf numbers.
(树型数值之和)
Note: A leaf is a node with no children.
Example:
1. DFS
常规的 DFS 算法,具体实现过程如下:
1 | # Definition for a binary tree node. |