← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Practice/Meta/Leetcode 129. Sum Root to Leaf Numbers
CodingMust
You are given a binary tree where each node contains a single digit from 0 to 9. Each path from the root to a leaf represents a number formed by concatenating the digits along that path in order.
Your task is to calculate the total sum of all numbers represented by root-to-leaf paths in the tree.
For example, if a path goes through nodes with values 1, 2, and 3 in that order, this path represents the number 123.
Example 1:
`
Input:
1
/
2 3
Output: 25 Explanation:
Example 2:
`
Input:
4
/
9 0
/
5 1
Output: 1026 Explanation:
Example 3:
` Input: 7
Output: 7 Explanation: The tree has only one node, which is also a leaf, representing the number 7 `