Numeros, The Artist, had two lists A and B, such that, B was a permutation of A. Numeros was very proud of these lists. Unfortunately, while transporting them from one exhibition to another, some numbers from List A got left out. Can you find out the numbers missing from A?

Notes

  • If a number occurs multiple times in the lists, you must ensure that the frequency of that number in both the lists is the same. If that is not the case, then it is also a missing number.
  • You have to print all the missing numbers in ascending order.
  • Print each missing number once, even if it is missing multiple times.
  • The difference between maximum and minimum number in the list B is less than or equal to 100.

Input Format 
There will be four lines of input:

n - the size of the first list 
This is followed by n space separated integers that make up the first list. 
m - the size of the second list 
This is followed by m space separated integers that make up the second list.

Output Format 
Output the missing numbers in ascending order

Constraints 
1<= n,m <= 1000010 
1 <= x <= 10000 , x ∈ B 
Xmax - Xmin < 101


题解:设置两个数组,因为x的范围在1~10000之间,只要开两个10001的数组分别记录A和B中元素的个数,然后比较两个数组就可以了。

代码如下:

 import java.util.*;

 public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] CountA = new int[10005];
int[] CountB = new int[10005]; int n = in.nextInt();
int[] a = new int[n];
for(int i = 0;i < n;i++){
a[i]=in.nextInt();
CountA[a[i]]++;
} int m = in.nextInt();
int[] b = new int[m];
for(int i = 0;i < m;i++){
b[i]=in.nextInt();
CountB[b[i]]++;
} for(int i = 1;i <= 10000;i++){
if(CountB[i]>CountA[i] )
System.out.printf("%d ", i);
}
System.out.println(); }
}

最新文章

  1. 使用VS2013进行单元测试
  2. Extended TCP/IP Stack In Linux: Netfilter Hooks and IP Table
  3. 反转链表,时间复杂度O(n),空间复杂度O(1)
  4. Android Immersive Mode (沉浸模式) 还是 Translucent Bars (透明状态栏)
  5. 【周年版】Cnblogs for Android
  6. JavaScript对象就是一组属性(方法)的集合
  7. Linux散列表(一)——操作函数
  8. 从栈不平衡问题 理解 calling convention
  9. (二十八)QQ好友列表的展开收缩
  10. rabbitmq之基本原理及搭建单机环境
  11. MySQL:select command denied to user for table 'proc'案例
  12. 如何设计一个restful风格的API
  13. java 注解 知识整理
  14. 剑指Offer_编程题_3
  15. 【设计模式】jdbc桥连接过程解析
  16. Redis 集群_主从配置_哨兵模式
  17. SQL SERVER SELECT语句中加锁选项的详细说明 [转]
  18. SpringBoot12 QueryDSL02之利用QueryDSL实现多表关联查询
  19. Python的一些技巧
  20. kvm网络虚拟化管理

热门文章

  1. php 设置地区时间
  2. IIS下PHP的ISAPI和FastCGI比较
  3. git commit --amend用法
  4. Apache:怎样利用.htaccess文件对PHP站点或文件进行伪静态处理
  5. shell脚本中echo显示内容带颜色显示
  6. 非jsonp解决跨域问题
  7. 构造方法、this和super
  8. GIT快速学习
  9. TP数据删除
  10. zend studio,操作记录