算法1
时间复杂度
O(n);
C++ 代码
using namespace std;
#include <iostream>
bool valid [1010] ;//定义布尔数组,标记有效数字
int main(){
int n;
cin>>n;
for (int i=0; i<n ; i++){
int temp;
cin>>temp;
valid [temp]=true;
}
for (int i=0; i<=n ; i++){
if ( valid [i] );
else {
cout << i ;
break;
}
}
return 0;
}