The TransCompilator

Solved LeetCode program · 112 of 1,000

#0112 · Path Sum

Easy Depth-First Search chunk-03.md

Original English source

Keep a shared values holding 5, 4, 8, 11, -1, 13, 4, 7, 2, -1, -1, -1, and 1. Keep a shared lefts holding 1, 3, 5, 7, 9, 11, -1, -1, -1, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, 8, 10, 12, -1, -1, -1, -1, -1, -1, and -1. Keep a shared target of 0. Keep a shared found of 0. Set target to 22.
To seek from node (a whole number) with total (a whole number). If found is 1, return. If node is less than 0, return. The sum is total 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 and sum is target, set found to 1, return. Seek from left with sum. Seek from right with sum.

Seek from 0 with 0. If found is 1, show true, otherwise show false.

Open in Playground Browse all 1,000 problems

Expected stdout

true