Give
nn
n non-negative integers, please find the least non-negative integer that doesn’t occur in the
nn
n numbers.
输入:
The first line is an integer
TT
T, representing the number of test cases.
For each test case:
The first line of each test case is an integer
nn
n.
The second line of each test case are
nn
n non-negative integers
aia_i
a
i
题意:给你n个数,找出缺失的第一个非负整数.
题解:用map标记已经出现过数,然后从 0 到 1<<31枚举,
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<unsigned,int> m;
int main(){
int t;
cin>>t;
while(t--){
m.clear();
int n;
cin>>n;
unsigned tmp;
for(int i=1;i<=n;i++){
scanf("%u",&tmp);
m[tmp]=1;
}
unsigned i=0;
while(i<=(1<<31)){
if(m[i]==0){
printf("%u\n",i);
break;
}
i++;
}
}
return 0;
}