题目
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 . 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 |
题解
思路
- 题目的意思是
- 给你一串数
- 让你从1,2,3,4,5一直到正无穷,找到第一个不在列表里的数
- 那么只要建立哈希集合,然后照着步骤来就可以了。
数据结构
- nums 是一个哈希集和,存放所有的数
算法
- 没啥算法
代码
- 由于使用Python能够AC,因此只放了Python的题解。
1 | _ = int(input()) |