用map记录一下key和value即可
#include<map>
class Solution {
public:
int MoreThanHalfNum_Solution(vector<int> array) {
if(array.size()==0){
return 0;
}
map<int,int> map1;
for(int i=0;i<array.size();i++){
map1[array[i]]++;
}
for(int i=0;i<map1.size();i++){
if(map1[array[i]]>(array.size()/2)){
return array[i];
}
}
return 0;
}
};