Untitled
unknown
plain_text
9 months ago
421 B
11
Indexable
HashMap<Integer, Integer> hm = new HashMap<Integer,Integer>();
for(int i = 0; i< A.length; i++){
if(hm.containsKey(A[i])){
hm.put(A[i] , hm.get(A[i]) + 1);
}else{
hm.put(A[i], 1);
}
}
for(int i = 0; i<A.length;i++){
if(hm.get(A[i]) > 1){
return A[i];
}
}
return -1;
}Editor is loading...
Leave a Comment