题解 | #缺失数字#

缺失数字

http://www.nowcoder.com/practice/9ce534c8132b4e189fd3130519420cde

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 找缺失数字
     * @param a int整型vector 给定的数字串
     * @return int整型
     */
    int solve(vector<int>& a) {
        vector<int>::iterator begin = a.begin();
        vector<int>::iterator end = a.end()-1;
        int temp = *end;
        if (*begin != 0) return 0; 
        while(begin!=end)
        {
            if(*(begin+1)!=*begin+1)
                return *begin+1;
            else
                begin++;
            if (*(end-1)!=*end-1)
                return *end-1;
            else
                end--;
        }
        return temp+1;
    }
};
全部评论

相关推荐

挣K存W养DOG:我记得好多人说这个公司就是白嫖方案的,现在有大体方案要让你给他展示实现细节了,也是无敌了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务