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(); }
}

【HackerRank】Missing Numbers的更多相关文章

  1. 【HackerRank】Closest Numbers

    Sorting is often useful as the first step in many different tasks. The most common task is to make f ...

  2. 【HDU3117】Fibonacci Numbers

    [HDU3117]Fibonacci Numbers 题面 求斐波那契数列的第\(n\)项的前四位及后四位. 其中\(0\leq n<2^{32}\) 题解 前置知识:线性常系数齐次递推 其实后 ...

  3. 【CF55D】Beautiful numbers(动态规划)

    [CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...

  4. 【CF628D】Magic Numbers 数位DP

    [CF628D]Magic Numbers 题意:求[a,b]中,偶数位的数字都是d,其余为数字都不是d,且能被m整除的数的个数(这里的偶数位是的是从高位往低位数的偶数位).$a,b<10^{2 ...

  5. 【CF55D】Beautiful numbers

    [CF55D]Beautiful numbers 题面 洛谷 题解 考虑到如果一个数整除所有数那么可以整除他们的\(lcm\),而如果数\(x\)满足\(x\bmod Lcm(1,2...,9)=r\ ...

  6. 【MAVEN】Missing artifact jdk.tools:jdk.tools:jar:1.6 eclipse

    搭建开发环境,遇到问题 : IDE 使用 eclipse 公司的项目用Maven管理,从git上拿下来代码后开始build后:    提示    [missing artifact jdk.tools ...

  7. 【数组】Missing Number

    题目: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is mi ...

  8. 【HackerRank】Running Time of Quicksort

    题目链接:Running Time of Quicksort Challenge In practice, how much faster is Quicksort (in-place) than I ...

  9. 【PYTHON】 Missing parentheses in call to 'print'

    Microsoft Windows [版本 10.0.15063] (c) 2017 Microsoft Corporation.保留所有权利. C:\Users\Jam>python Pyth ...

随机推荐

  1. spark单机模式

    1.下载spark,解压2.复制conf/spark-env.sh和conf/log4j.properties cp spark-env.sh.template spark-env.sh cp log ...

  2. 调试node.js应用--node-inspector

    如果你在编写Node.js代码,node-inspector是必备之选,比Node.js的内置调试器好出许多.使用起来跟Chrome的javascript调试器很相似. 使用npm安装: $ npm ...

  3. Sping 的 BeanFactory 容器

    Sping 的 BeanFactory 容器 这是一个最简单的容器,它主要的功能是为依赖注入 (DI) 提供支持,这个容器接口在 org.springframework.beans.factory.B ...

  4. python3----基础函数的参数是可变参数,将传进来的参数转成列表

    def myFun(*argments): values = [x for x in argments] print(values) myFun(1,2,3,4,5,6) result: [1, 2, ...

  5. mysqldump: Got error: 1045

    问题:最近备份mysql然后在执行mysqldump的时候提示权限和密码有问题 报错: Warning: Using a password on the command line interface ...

  6. 错误命令“if not exist "\Dll" mkdir "\Dll" xcopy "\bin\Debug\*.*" "F:\647\VS项目\EtrolMes2014SY\Framework\Dll" /e /i /y”已退出,代码为 9009

    分析错误 第一步:观察错误,发现plugin文件夹中未生成对应的编译文件. 第二步:XCOPY命令无法执行,百度xcopy为何无法执行 第三步,搜索,发现环境变量未配置正确. 就是环境变量path(大 ...

  7. 3993: [SDOI2015]星际战争

    3993: [SDOI2015]星际战争 Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 1244  Solved: ...

  8. RTSP安防摄像机(海康大华宇视等)如何推送到RTMP流媒体服务器进行直播

    方案介绍 目前互联网直播的CDN和标准RTMP流媒体服务器通常只能接收RTMP格式的音视频推流.目前市场上有一些自带RTMP推流的摄像机和编码器,可以直接在其rtmp推流配置里面配置推送到RTMP流媒 ...

  9. 利用jdk中工具完成Java程序监控方法记录

    转载加自己整理的部分内容,转载自:http://jiajun.iteye.com/blog/810150 记录下JConsole使用方法 一.JConsole是什么    从Java 5开始 引入了 ...

  10. 如何搭建一个 Git 版本控制服务端?

    Gogs 下载和安装 https://github.com/gogits/gogs # 下载二进制压缩包 不检查服务器证书 root@cheungxiongwei:~# wget --no-check ...