The TransCompilator

Solved LeetCode program · 199 of 1,000

#0229 · Majority Element II

Medium Array chunk-04.md

Original English source

Keep a shared numbers holding 3, 2, and 3. Keep a shared last of 2. Keep a shared count of 0. Keep a shared duplicate of 0.
To tally from target (a whole number). Set count to 0.
For every other from 0 to last.
If item other of numbers is item target of numbers, add 1 to count.

To check from target (a whole number). Set duplicate to 0.
For every prior from 0 to last.
If prior is less than target and item prior of numbers is item target of numbers, set duplicate to 1.

For every spot from 0 to last.
Tally from spot. Check from spot. If count times 3 is more than 3 and duplicate is 0, show item spot of numbers.

Open in Playground Browse all 1,000 problems

Expected stdout

3