import java.util.*;
class Solution {
public int solution(int[] array) {
HashMap<Integer, Integer> map = new HashMap<>();
for (int n : array) {
int cnt = map.getOrDefault(n, 0) + 1;
map.put(n, cnt);
}
int ans = 0;
int max = 0;
Boolean find = false;
for (int n : map.keySet()) {
if (max < map.get(n)) {
ans = n;
max = map.get(n);
find = false;
}
else if (max == map.get(n) && find == false)
find = true;
}
if (find)
return -1;
return ans;
}
}
import java.util.*;
class Solution {
public int solution(int[] array) {
Map<Integer, Integer> map = new HashMap<>();
for (int num : array) {
map.put(num, map.getOrDefault(num, 0) + 1);
}
int answer = -1;
int maxcnt = 0;
for (int key : map.keySet()) {
int cnt = map.get(key);
if (cnt > maxcnt) {
maxcnt = cnt;
answer = key;
} else if (cnt == maxcnt) {
answer = -1;
}
}
return answer;
}
}