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. E - Leading and Trailing 求n^k得前三位数字以及后三位数字,保证一定至少存在六位。

    /** 题目:E - Leading and Trailing 链接:https://vjudge.net/contest/154246#problem/E 题意:求n^k得前三位数字以及后三位数字, ...

  2. Spring MVC3.0.5搭建全程

    http://aokunsang.iteye.com/blog/1279322 ——————————————————————————————————————————————————

  3. 通知:spark meetup 第六次会议在北京举行

    通知: Spark北京Meetup第六次活动(­机器学习专题) 将于北京时间3月21日 下午14:00-18:00 在微软亚太研发集团总部大厦1号楼举行,主题包括: Julien Pierre  Pr ...

  4. [ JS 进阶 ] 基本类型 引用类型 简单赋值 对象引用 (转)

    ECMAScirpt 变量有两种不同的数据类型:基本类型,引用类型.也有其他的叫法,比如原始类型和对象类型,拥有方法的类型和不能拥有方法的类型,还可以分为可变类型和不可变类型,其实这些叫法都是依据这两 ...

  5. python爬虫:正则表达式

    符号: . : 匹配任意字符(类似占位符,多少个.就表示多少个字符),换行符除外(与re.S相反) *:匹配前面一个字符0次或无限次 ?:匹配前面一个字符0次或1次 组合: .* : 贪心算法 一次匹 ...

  6. Laragon集成开发环境+配置Xdebug+postman运行Xdebug

    [ Laravel 5.5 文档 ] 快速入门 —— 使用 Laragon 在 Windows 中搭建 Laravel 开发环境:http://laravelacademy.org/post/7754 ...

  7. Spring 中的 Resource和ResourceLoader

    Spring 内部框架使用org.springframework.core.io.Resource接口作为所有资源的抽象和访问接口.Resource接口可以根据资源的不同类型,或者资源所处的不同场合, ...

  8. Android开发:《Gradle Recipes for Android》阅读笔记(翻译)2.3——用Eclipse ADT导出App

    问题: 想在一个已经存在的Eclipse ADT的项目中使用Gradle 解决方案: Eclipse ADT插件可以帮助生成Gradle文件 讨论: Eclipse的ADT插件是在2013年推出Gra ...

  9. [Sdoi2011]火星移民

    2283: [Sdoi2011]火星移民 Time Limit: 40 Sec  Memory Limit: 512 MBSubmit: 119  Solved: 56[Submit][Status] ...

  10. 常见cout格式输出

    cout.setf(ios::fixed);//设置格式 cout.unsetf(ios::fixed);//取消格式 cout.setf(ios::scientific);//科学记数法 cout. ...