The TransCompilator

Solved LeetCode program · 129 of 1,000

#0129 · Sum Root to Leaf Numbers

Medium Depth-First Search chunk-03.md

Original English source

Keep a shared values holding 1, 2, and 3. Keep a shared lefts holding 1, -1, and -1. Keep a shared rights holding 2, -1, and -1. Keep a shared total of 0.
To walk from node (a whole number) with value (a whole number). If node is less than 0, return. The current is value times 10 plus item node of values. The left is item node of lefts. The right is item node of rights. If left is -1 and right is -1, add current to total, return. Walk from left with current. Walk from right with current.

Walk from 0 with 0. Show total.

Open in Playground Browse all 1,000 problems

Expected stdout

25