文章目录
- AcWing 68. 0到n-1中缺失的数字
- AC代码
AcWing 68. 0到n-1中缺失的数字
本博客给出本题截图:
AC代码
代码:
class Solution { public: int getMissingNumber(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; } };