The TransCompilator

Solved LeetCode program · 938 of 1,000

#1302 · Deepest Leaves Sum

Medium Depth-First Search chunk-19.md

Original English source

Keep a shared values holding 1, 2, 3, 4, 5, -1, 6, 7, -1, -1, -1, -1, and 8. Keep a shared lefts holding 1, 3, 5, 7, 9, -1, 11, -1, -1, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, 8, 10, -1, 12, -1, -1, -1, -1, -1, and -1. Keep a shared best of 0. Keep a shared total of 0.

To measure from node (a whole number) with level (a whole number). If node is less than 0, return. If item node of values is less than 0, return. If level is more than best, set best to level. Measure from item node of lefts with level plus 1. Measure from item node of rights with level plus 1.

To gather from node (a whole number) with level (a whole number). If node is less than 0, return. If item node of values is less than 0, return. If level is best, set total to total plus item node of values. Gather from item node of lefts with level plus 1. Gather from item node of rights with level plus 1.

Measure from 0 with 0. Gather from 0 with 0. Show total.

Open in Playground Browse all 1,000 problems

Expected stdout

15