The TransCompilator

Solved LeetCode program · 463 of 1,000

#0653 · Two Sum IV - Input is a BST

Easy Depth-First Search chunk-10.md

Original English source

Keep a shared values holding 5, 3, 6, 2, 4, and 7. Keep a shared lefts holding 1, 3, 5, -1, -1, and -1. Keep a shared rights holding 2, 4, -1, -1, -1, and -1. Keep a shared order as an empty list of whole numbers.
To gather from node (a whole number). If node is less than 0, return. Gather from item node of lefts. Place item node of values into order. Gather from item node of rights.

Gather from 0. The wanted is 9. The left is 0. The right is the last position of order. The found is 0.
Repeat while left is less than right.
The pair is item left of order plus item right of order. If pair is wanted, set found to 1, stop. If pair is less than wanted, add 1 to left. If pair is more than wanted, subtract 1 from right.

If found is 1, show true, otherwise show false.

Open in Playground Browse all 1,000 problems

Expected stdout

true