剑指Offer-Week6
68. 0到n-1中缺失的数字

https://www.acwing.com/problem/content/64/
思路:
剑指Offer-Week6_编程题

class Solution {
public:
    int getMissingNumber(vector<int>& nums) {
        int l = 0,r = nums.size();
        if(r == 0){
            return 0;
        }
        int ans = 0;
        //二分查找第一个nums[i]!=i的下标
        while(l < r){
            int mid = (l + r) >> 1;
            if(nums[mid] == mid){
                l = mid + 1;
            }
            else {
                r = mid;
            }
        }
        return l;
    }
};