Given an array nums of size n, return the majority element.
nums
n
The majority element is the element that appears more than n / 2 times. You may assume that the majority element always exists in the array.
n / 2
nums = [3,2,3]
3
nums = [2,2,1,1,1,2,2]
2
1 <= nums.length <= 5 * 10^4 -10^9 <= nums[i] <= 10^9
Topics
Implement majorityElement in the editor and return the answer — printing it is never graded.
majorityElement
Problem 15 of 1146 in the arena