Sum Root to Leaf Numbers
Each root-to-leaf path spells a number; return the sum of all such numbers.
Open on LeetCode ↗Intuition
Summing digit values as you go, or building a string along the path and parsing it at the leaf, both technically work but miss the clean trick: carry the number itself down the recursion with cur = cur * 10 + node.val. The multiply-by-10 IS the place-value shift that a string concatenation is imitating the hard way. Only add cur to the running total when you hit an actual leaf -- adding at every node would count partial paths that were never meant to be numbers.
Approach
Carry the running number down
At each node, cur = cur * 10 + node.val -- this is the number formed by the path from the root to this node, kept correct at every depth without any string work.
Only total at leaves
If a node has no left and no right child, add cur to the running total -- it is a complete root-to-leaf number.
Recurse both sides with the updated cur
Pass the new cur value into both children; each subtree continues extending its own copy of the path number independently.
Solution & live demo
Edge cases
Return 0, no paths exist.
That node is itself both root and leaf; its value is the sum.
cur starts at 0*10+0=0, still correct -- leading zero paths are fine since LeetCode guarantees no path represents a number with a leading zero beyond the root itself.
cur grows correctly at each level via the *10 shift regardless of tree shape.