public static void main(String[] args) {
int[] aa = {1,2,2,3,4,1,5};
returnMost(aa);
}
public static int returnMost(int[] arr){
if (arr == null || arr.length == 0)
return 0;
int Max= 0;
int result = 0;
HashMap<Integer,Integer> map = new HashMap<>();
for (int i : arr) {
map.merge(i, 1, Integer::sum);
if (map.get(i) >= Max) {
Max = map.get(i);
result = i;
}
}
return result;
}
网友评论