Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.Array;
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- public class Main
- {
- public static void main (String[] args) throws java.lang.Exception
- {
- //your code here
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int[] first = new int[n];
- for (int i=0;i<n;i++)
- first[i] = sc.nextInt();
- int m = sc.nextInt();
- int[] second = new int[m];
- for (int i=0;i<m;i++)
- second[i] = sc.nextInt();
- ArrayList<Integer> ans = new ArrayList<>();
- HashMap<Integer, Integer>hashMap = new HashMap<>();
- for(int i: second)
- hashMap.put(i, hashMap.getOrDefault(i, 0) - 1);
- for(int i: first)
- hashMap.put(i, hashMap.getOrDefault(i, 0) + 1 );
- // for(Map.Entry<Integer, Integer> curr: hashMap.entrySet()) {
- // if(curr.getValue() != 0) {
- // ans.add(curr.getKey());
- // }
- // }
- for(int i: second){
- if(hashMap.get(i)!=0){
- ans.add(i);
- hashMap.put(i,0);
- }
- }
- for(int i: first){
- if(hashMap.get(i)!=0){
- ans.add(i);
- hashMap.put(i,0);
- }
- }
- Collections.sort(ans);
- for (int x : ans)
- System.out.print(x + " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement