class Solution {
public int majorityElement(int[] nums) {
Map<Integer,Integer> map = new HashMap<Integer,Integer>();
int n = nums.length;
for(int num : nums){
Integer count = map.get(num);
if(count == null){
count = 1;
}else{
count++;
}
map.put(num, count);
if(map.get(num) > n/2){
return num;
}
}
return 0;
}
}