129 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.
For example,
The root-to-leaf path1->2
represents the number12
.
The root-to-leaf path1->3
represents the number13
.
Return the sum = 12 + 13 =25
.
这题应该是假设了从root到leaf的数字不会超出int,不然我的方法可能不过。做完对个答案又被大神们的代码给秒了。
某大神的代码:
Last updated