剑指OFFER----面试题53 - II. 0~n-1中缺失的数字
链接:https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/
代码
class Solution {
public:
int missingNumber(vector<int>& nums) {
if (nums.empty()) return 0;
int l = 0, r = nums.size() - 1;
while (l < r) {
int mid = l + r >> 1;
if (nums[mid] != mid) r = mid;
else l = mid + 1;
}
if (nums[r] == r) r++;
return r;
}
};