-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicateNumberInArray.java
More file actions
31 lines (28 loc) · 746 Bytes
/
DuplicateNumberInArray.java
File metadata and controls
31 lines (28 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.*;
import java.util.Map.Entry;
import java.util.Hashtable;
class DuplicateNumberInArray
{
public static void findDuplicate(int[] arr){
Hashtable<Integer,Integer> hst = new Hashtable<Integer,Integer>();
for(int i = 0 ; i < arr.length ; i++){
if(hst.isEmpty()){
hst.put(arr[i],1);
}else if(hst.containsKey(arr[i])){
hst.put(arr[i],hst.get(arr[i]) + 1);
}else{
hst.put(arr[i],1);
}
}
for(Entry<Integer,Integer> entry : hst.entrySet()){
if(entry.getValue() > 1){
System.out.println("Duplicate value :: " + entry.getKey());
}
}
}
public static void main(String[] args)
{
int[] arr = {10,20,30,2,10,20,11,204,221,12,30};
findDuplicate(arr);
}
}