题解 | #序列找数#

序列找数

https://www.nowcoder.com/practice/a7d1856a72404ea69fdfb5786d65539c

#include <iostream>
using namespace std;

int main() {
    int n;
    while (cin >> n) {
        int* input = new int[n+1]();
        int in;
        for(int i = 0;i < n+1;i++){
            cin >> in;
            input[in] = 1;
        }
        for(int i = 0;i < n+2;i++){
            if (input[i] == 0){
                cout << i <<endl;
                break;
            }
        }
        delete []input;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

用数组来保存输入过的数字,比较笨逼,但是如果有重复输入也可以处理

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务