vector<int> findErrorNums(vector<int>& nums) {
    const int N = 10001;
    int S[N];

    int n = nums.size();

    for (int i = 0; i < N; i++)
    {
        S[i] = 0;
    }

    for (int i = 1; i <= n; i++)
    {
        int m = nums[i - 1];
        S[m]++;
    }

    int dup = -1;
    int miss = -1;

    for (int i = 1; i <= n; i++)
    {
        if (S[i] == 2 && dup == -1)
        {
            dup = i;
        }
        if (S[i] == 0 && miss == -1)
        {
            miss = i;
        }

    }
    vector<int> R;
    R.push_back(dup);
    R.push_back(miss);

    return R;
}

 

posted on 2018-09-26 17:50  Sempron2800+  阅读(91)  评论(0编辑  收藏  举报