import java.util.HashMap;
public class Solution {
public static int majorityElement(int []v) {
// Write your code here
HashMap<Integer,Integer> map = new HashMap<>();
int max = 0, val = v[0];
for(int i=0;i<v.length;i++){
map.put(v[i],map.getOrDefault(v[i], 0)+1);
int value = map.get(v[i]);
if(map.get(v[i])>max){
max = map.get(v[i]);
val = v[i];
if(max > v.length/2) return val;
}
}
return val;
}
}