import java.util.*;
public class Solution {
public int MoreThanHalfNum_Solution(int [] array) {
int x = -1;
int count = 0;
Arrays.sort(array);
for (int i = 0; i < array.length; i++) {
if (x != array[i]) { //如果当前数组值和保存的值不同,则更新,并重新计数
x = array[i];
count = 0;
}
count++;
if (count > array.length / 2) break; //超过一半,跳出
}
return x;
}
}