50: Binary tree sum numbers

Given a binary tree, each node has a value from 0 to 9. Each path from a root to a leaf represents a number, return a sum of all these numbers

 

Example 1

Input:     1   
          / \  
         5   4 

Output: 29

Explanation: 1 -> 5 = 15, 1 -> 4 = 14, 15 + 14 = 29

Example 2

Input:        1  
             / \
            2   3
           /   /
          4   5  
             / \ 
            6   0 

Output: 2830

Explanation: 1 -> 2 -> 4 = 124, 1 -> 3 -> 5 -> 6 = 1356, 1 -> 3 -> 5 -> 0 = 1350

Difficulty:Medium
Topic:Tree
Problem #:50