import java.util.Arrays;

public class Solution {
    public int MoreThanHalfNum_Solution(int [] array) { //先排序,在计算 时间复杂度O(logn),空间复杂度O(1)。
         Arrays.sort(array);
        int max = 1;
        int before = array[0];
        for (int i = 1; i < array.length; i++) {
            if (before == array[i]) {
                max++;
            } else {
                before = array[i];
                max = 1;
            }
            if (max > array.length / 2) {
                return array[i];
            }
        }
        return before;
        
    }
}