题解 | #序列找数#
序列找数
https://www.nowcoder.com/practice/a7d1856a72404ea69fdfb5786d65539c
#include <iostream>
#include <set>
using namespace std;
int main() {
int n, temp;
cin >> n;
set<int> a;
int b[n];
for(int i = 0; i < n; i++){
scanf("%d ", &temp);
b[i] = temp;
}
a.insert(b, b + n);
int c = 0;
for(set<int>::iterator it = a.begin(); it != a.end(); it++){
if(c == *it){
c++;
}
else {
cout << c;
break;
}
}
return 0;
}
这题开始想的是用c语言做,后来发现,使用集合自动排序以及不重复元素的特性,可以直接迭代找出结果
查看19道真题和解析
