129. Sum Root to Leaf Numbers

Practice Sum Root to Leaf Numbers for free on NudgeCode: Medium, Binary Tree pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Every node of a non-empty binary tree holds a single digit 0-9. Reading a root-to-leaf path from top to bottom spells a decimal number (the path 1 -> 2 -> 3 is 123). Return the sum of the numbers spelled by all root-to-leaf paths.

Trees are written in level order, with null for a missing child.

Example

root = [1,2,3]  ->  25   (12 + 13)

Constraints