Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.
public class Solution {
public int majorityElement(int[] num) {
if (num.length == 1) {
return num[0];
}
Arrays.sort(num); //快排
return num[num.length / 2]; 取中
}
}