The TransCompilator

Solved LeetCode program · 161 of 1,000

#0169 · Majority Element

Easy Array chunk-04.md

Original English source

The numbers is a list of 2, 2, 1, 1, 1, 2, and 2. The candidate is item 0 of numbers. The score is 0.
For each value in numbers.
If score is 0, set candidate to value. If value is candidate, add 1 to score. If value is not candidate, subtract 1 from score.

Show candidate.

Open in Playground Browse all 1,000 problems

Expected stdout

2