Majority Element
Easy
Arrays
Array
Hash Table
Sorting
Given an array, find the element that appears more than n/2 times.
Constraints
n ≥ 1, majority always exists
Examples
Example 1:
Input: 3 2 3
Output: 3
Example 2:
Input: 2 2 1 1 1 2 2
Output: 2
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console