寻找数组中缺少的第一个连续正整数--Set
1. 原文
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 |
2. 解析
输入的值可能重复
set去重且从小到大排序 只能用for循环找到值
从idx=1开始 if(idx==*i) idx++;
最终idx值即为缺少的值
3. AC代码
1 |
|
值要去重
Gitalking ...