← 返回 meta 的题目列表Majority Element
类型:online_judge
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element always exists in the array. Write a function to solve this problem.
Example:
Input: [3,2,3] Output: 3
Input: [2,2,1,1,1,2,2] Output: 2
Constraints:
1 <= n <= 5 * 10^4
-10^9 <= nums[i] <= 10^9
Example
Input
[3,2,3]