题解 | #序列找数#

序列找数

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

#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main() {
    int N;
    while(cin>>N){
        set<int> num;
        vector<int> vec;
        while(N--){
            int temp;
            cin>>temp;
            num.insert(temp);
        }

        auto it1=num.begin();
        auto it2=--num.end();
        if(*it1==1){
            cout<<0;
            return 0;
        } 
        if(*it2==N-1){
            cout<<N;
            return 0;
        }
        for(auto it = num.begin(); it!=num.end(); it++){
            vec.push_back(*it);
        }

        for(int i=0; i<vec.size(); i++){
            if(vec[i]+1!=vec[i+1]){
                cout<<vec[i]+1;
                return 0;
            }
        }

        }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 11:29
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 12:10
点赞 评论 收藏
分享
05-27 14:57
西北大学 golang
强大的社畜在走神:27届真不用急,可以搞点项目、竞赛再沉淀沉淀,我大二的时候还在天天打游戏呢
投递华为等公司10个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 11:20
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务