8. Majority Vote
easyarraycounting
Return the element that appears more than n / 2 times in nums. Such an element is guaranteed to exist.
Example 1
Inputnums = [3,2,3]
Output3
Example 2
Inputnums = [2,2,1,1,1,2,2]
Output2
Constraints
- 1 ≤ n ≤ 5·10⁴
Hint 1
Boyer–Moore voting finds it in one pass and O(1) space.