Approach Summary
DFS: carry running number = prev * 10 + node.val. At each leaf, add the running number to the total.
How to Recognize This Pattern
- Root-to-leaf paths form numbers
- Accumulate digit: num = parent_num * 10 + curr_digit
Complexity Analysis
Time Complexity
O(n)
Space Complexity
O(h)
Tags
Tree DFS BFS Binary Tree