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. php5.4n 长链接 bug

    运行5.2的部分程序会有中文无法显示的问题 恢复到5.2后中文显示正常

  2. IDEA15入门常用设置

    打开IDEA设置的快捷键:Ctrl + Alt + S 打开选中的项目属性快捷键:Shift + Ctrl + Alt + S 1.IDEA默认不会使用我们独立安装的Maven配置,需要手动设置,并且 ...

  3. ASP.NET动态网站制作(27)-- 三层框架(1)

    前言:今天主要介绍一下三层框架,给大家一个整体的概念.分层概念使得程序低耦合,更加健壮,扩展性更好. 内容: 1.三层: UI(表现层):主要是指与用户交互的界面.用于接收用户输入的数据和显示处理后用 ...

  4. PDP2

    1. 程序入口 配置文件config.xml中: 2. index.html中显示,引入的cordova.js 就说明了 cordova apps 3. 看 main.ts

  5. poj2420(模拟退火大法好)

    // // main.cpp // poj2420 // // Created by 陈加寿 on 16/2/13. // Copyright © 2016年 chenhuan001. All rig ...

  6. 3280 easyfinding

    3280 easyfinding  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 给一个M ...

  7. 使用MyBatis_Generator工具jar包自动化生成Dto、Dao、Mapping 文件

    由于MyBatis属于一种半自动的ORM框架,所以主要的工作将是书写Mapping映射文件,但是由于手写映射文件很容易出错,所以查资料发现有现成的工具可以自动生成底层模型类.Dao接口类甚至Mappi ...

  8. JavaScript Array 对象(length)方法 (contact、push,pop,join,map、reverse、slice、sort)

    一.Array对象属性 1.length 设置或返回数组中元素的数目. 数组的 length 属性总是比数组中定义的最后一个元素的下标大 1.对于那些具有连续元素,而且以元素 0 开始的常规数组而言, ...

  9. git 中 A C D M R T U X 分别解释

    git 中 A C D M R T U X 分别解释 - CSDN博客 https://blog.csdn.net/adminyan/article/details/64922979 A: 你本地新增 ...

  10. python系列七:Python3字典dict

    #!/usr/bin/python #Python3 字典#字典是支持无限极嵌套的citys={    '北京':{        '朝阳':['国贸','CBD','天阶','我爱我家','链接地产 ...