Sum Root to Leaf Numbers

Problem Each tree node holds a digit 0–9; every root-to-leaf path spells a number. Return the sum of all such numbers.

Input / Output

  • Input: tree root. Output: total sum.

Constraints

  • Up to 1000 nodes, depth <= 10 (sums fit in int); O(n) required.

Example

  • [1,2,3] → 12 + 13 = 25; [4,9,0,5,1] → 495 + 491 + 40 = 1026.
asked …
LeaderboardSalaryAccount