The TransCompilator

Solved LeetCode program · 786 of 1,000

#1022 · Sum of Root To Leaf Binary Numbers

Easy Depth-First Search chunk-16.md

Original English source

Keep a shared values holding 1, 0, 1, 0, 1, 0, and 1. Keep a shared lefts holding 1, 3, 5, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, -1, -1, -1, and -1. Keep a shared total of 0.

To gather from node (a whole number) with path (a whole number). If node is less than 0, return. The carried is path times 2 plus item node of values. The left is item node of lefts. If left is less than 0 and item node of rights is less than 0, add carried to total, return. Gather from left with carried. Gather from item node of rights with carried.

Gather from 0 with 0. Show total.

Open in Playground Browse all 1,000 problems

Expected stdout

22