-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemDups.java
More file actions
39 lines (32 loc) · 976 Bytes
/
RemDups.java
File metadata and controls
39 lines (32 loc) · 976 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
32
33
34
35
36
37
38
39
import java.util.*;
public class RemDups {
public static void main(String args[]){
LinkedList<Integer> lis = new LinkedList<>();
HashSet<Integer> set = new HashSet<>();
lis.add(1);
lis.add(4);
lis.add(3);
lis.add(4);
lis.add(2);
// for(Integer e: lis){
// System.out.print(e + " ");
// }
for(int i =0; i<lis.size()-1;i++){
for(int j = i+1; j<lis.size(); j++){
if(lis.get(i) == lis.get(j)){
set.add(lis.get(i));
}
}
}
// for(int i = 0; i<lis.size(); i++){
// if(set.contains(lis.get(i))){
// lis.removeAll(set);
// }
// }
lis.removeAll(set);
Iterator it = lis.iterator();
while(it.hasNext()){
System.out.print(it.next()+" ");
}
}
}