The TransCompilator

Solved LeetCode program · 372 of 1,000

#0501 · Find Mode in Binary Search Tree

Easy Depth-First Search chunk-08.md

Original English source

Keep a shared values holding 1, 2, and 2. Keep a shared lefts holding -1, 2, and -1. Keep a shared rights holding 1, -1, and -1. Keep a shared order as an empty list of whole numbers. Keep a shared occurrences of 0.

To walk from node (a whole number). If node is less than 0, return. Walk from item node of lefts. Place item node of values into order. Walk from item node of rights.

To tally from spot (a whole number) with target (a whole number). If spot is more than the last position of order, return. If item spot of order is target, add 1 to occurrences. Tally from spot plus 1 with target.

Walk from 0. Sort order. The best is 0.
For each value in order.
Set occurrences to 0. Tally from 0 with value. If occurrences is more than best, set best to occurrences.

The answers is an empty list of whole numbers.
For each value in order.
Set occurrences to 0. Tally from 0 with value. If occurrences is best and answers does not contain value, Place value into answers.

For each value in answers, show value.

Open in Playground Browse all 1,000 problems

Expected stdout

2