File tree 1 file changed +37
-0
lines changed
DataStructures/HashMap/Hashing
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java.util.ArrayList;
2
+ import java.util.HashMap;
3
+ import java.util.Map;
4
+ import java.util.Scanner;
5
+ import java.util.Set;
6
+
7
+ public class Intersection {
8
+
9
+ public static ArrayList Main(int arr[],int arr2[]) {
10
+ HashMap<Integer,Integer> hmap=new HashMap<>();
11
+ HashMap<Integer,Integer> hmap2=new HashMap<>();
12
+ for(int i=0;i<arr.length;i++) {
13
+ if(hmap.containsKey(arr[i])) {
14
+ int val=hmap.get(arr[i]);
15
+ hmap.put(arr[i],val+1);
16
+ }else
17
+ hmap.put(arr[i],1);
18
+
19
+ }
20
+ ArrayList<Integer> res=new ArrayList<>();
21
+ for(int i=0;i<arr2.length;i++) {
22
+ if(hmap.containsKey(arr2[i])&&hmap.get(arr2[i])>0) {
23
+ int val=hmap.get(arr2[i]);
24
+ hmap.put(arr2[i],val-1);
25
+ res.add(arr2[i]);
26
+ }
27
+
28
+ }
29
+ return res;
30
+ }
31
+ public Intersection() {
32
+
33
+ }
34
+
35
+
36
+
37
+ }
You can’t perform that action at this time.
0 commit comments