Summing Root-to-Leaf Numbers In Binary Tree
Sum Root to Leaf Numbers: Use DFS to traverse binary tree & calculate sum of root-to-leaf numbers. Example inputs: [1,2,3] & [4,9,0,5,1]. Output: 25 & 1026 respectively.
129. Sum Root to Leaf Numbers Difficulty: Medium Topics: Tree, Depth-First Search, Binary Tree You are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number. For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123. Return the total sum of all root-to-leaf numbers. Test cases are generated so that the answer will fit in a 32-bit integer. A leaf node is a node with no children. Example 1: Input: root = [1,2,3] Output: 25 Explanation: The root-to-leaf path 1->2 represents the number 12. The root-to-leaf...