1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| class Solution {
public int solution(int[] array) {
int answer=0;
int[] index=new int[array.length+1];
int max=Integer.MIN_VALUE;
for(int i=0; i<array.length; i++){
index[array[i]]++;
}
for(int i=0; i<index.length; i++){
if(index[i]>max){
max=index[i];
answer=i;
}else if(index[i]==max)
answer=-1;
else
continue;
}
return answer;
}
}
|