1144 The Missing Number
题目
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (≤105). Then N integers are given in the next line, separated by spaces. All the numbers are in the range of int.
Output Specification:
Print in a line the smallest positive integer that is missing from the input list.
Sample Input:
1 | 10 |
Sample Output:
1 | 7 |
题意
给定N个数,要求找出不在列表内的最小正整数.
思路
这道题如果没有理解题目就会跑偏了,题目要求找出不在列表内的最小正整数,也就是说如果1不在列表里,那1就是我们要找的那个最小正整数.
不管输入的列表有多少个数,我们都只需要在循环内从1开始比较,只要发现某个数不存在,那就输出这个数.
但是因为输入的数字列表是无序的,所以我们要将这些数字放入一个集合中.
代码
1 | public static void Main() |