Q129. Sum Root to Leaf Numbers
PreviousQ117. Populating Next Right Pointers in Each Node IINextQ144. Binary Tree Preorder Traversal
Last updated
Was this helpful?
Last updated
Was this helpful?
直达:
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
.
类似于 不同之处在于去路径之和的时候要对之前的路径乘以10。