If the depth of a tree is smaller than5, then this tree can be represented by a list of three-digits integers.
For each integer in this list:
The hundreds digit represents the depth
Dof this node,1 <= D <= 4.
The tens digit represents the positionPof this node in the level it belongs to,1 <= P <= 8
. The position is the same as that in a full binary tree.
The units digit represents the valueVof this node,0 <= V <= 9.
Given a list ofascendingthree-digits integers representing a binary with the depth smaller than 5. You need to return the sum of all paths from the root towards the leaves.
Example 1:
Input:
[113, 215, 221]
Output:
12
Explanation:
The tree that the list represents is:
3
/ \
5 1
The path sum is (3 + 5) + (3 + 1) = 12.