题目描述:
Give nn non-negative integers, please find the least non-negative integer that doesn’t occur in the nn numbers.
输入:
The first line is an integer TT, representing the number of test cases.
For each test case:
The first line of each test case is an integer nn.
The second line of each test case are nn non-negative integers a_ia i .T \leq 10T≤10n \leq 2 \times 10^5n≤2×10 5 0 \leq a_i < 2^{31}0≤a i<2 31
输出:
or each test case, output a line with the answer.
样例输入
2
4
4 0 1 3
2
1 1
样例输出
2
0
// 佛祖保佑代码无bug
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// .' \\| |// `.
// / \\||| : |||// \
// / _||||| -:- |||||- \
// | | \\\ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// 美女保佑代码无BUG
// .::::.
// .::::::::.
// :::::::::::
// ..:::::::::::'
// '::::::::::::'
// .::::::::::
// '::::::::::::::..
// ..::::::::::::.
// ``::::::::::::::::
// ::::``:::::::::' .:::.
// ::::' ':::::' .::::::::.
// .::::' :::: .:::::::'::::.
// .:::' ::::: .:::::::::' ':::::.
// .::' :::::.:::::::::' ':::::.
// .::' ::::::::::::::' ``::::.
// ...::: ::::::::::::' ``::.
// ````':. ':::::::::' ::::..
// '.:::::' ':'````..
//
//
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<vector>
#define ll long long
#define dd double
using namespace std;
ll a[200005];
int main() {
ll t, n;
cin >> t;
while (t--) {
ll flag = 0;
cin >> n;
memset(a, 0, sizeof(a));
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
if (a[0] != 0) {
cout << "0" << endl;
continue;
}
ll z = a[0];
ll q = 1;
for (ll i = 1; i < n; i++) {
if (a[i] != z + q) {
if (a[i] >= 0 && a[i] <= z + 1) {
continue;
}
}
else if (a[i] == z + q) {
z++;
}
else {
flag = 1;
cout << z + q << endl;
}
}
if (flag == 0) {
cout << z + q << endl;
}
}
}