Majority element
Easyarraycountingboyer-moore
One value appears more than half the time in nums. Return it. Try O(1) memory.
Example 1
Input: nums = [3,2,3] Output: 3
Example 2
Input: nums = [2,2,1,1,1,2,2] Output: 2
Constraints
- 1 ≤ nums.length ≤ 5·10⁴
- A majority element always exists
Submit checks your solution against 7 tests, including hidden ones.
/**
* @param {int[]} nums
* @return {int}
*/
function majorityElement(nums) {
}