1.第一种思路:通过使用hashmap,存储对应的数字以及它出现的次数,最后遍历hashmap,返回其次数大于数组一半的那个数字
2.第二种思路:使用摩尔投票法;
选定数组中的第一个数组
int num=arr[0];
int count=0;
for(int i=1;i<arr.length-1;i++){
if(arr[i]!=num)}{
//如果不相等的话就将其count --;
count--;
if(count<0){
num=arr[i];
count=0;
}
else{
count++;
}}
return count;