Example 1
Input
nums = [3, 2, 3]
Output
3
Loading CodeSprint...
/problems/majority-element
Return the value that appears more than half the time in a nonempty integer list. Such a value is guaranteed to exist.
Implement this function and return the result. CodeSprint supplies each test case automatically.
majorityElement(nums) → numberInput
nums = [3, 2, 3]
Output
3
Input
nums = [2, 2, 1, 1, 1, 2, 2]
Output
2
Constraints
1 <= nums.length <= 100,000 -1,000,000,000 <= nums[i] <= 1,000,000,000