class Solution {
public:
int getNumberSameAsIndex(vector<int>& nums) {
//二分,单调性序列,nums[i] - i,我们需要找到一个nums[i] - i == 0的数
if(nums.empty()) return -1;
int l = 0,r = nums.size() - 1;
while(l < r){
int mid = l + r >> 1;
if(nums[mid] - mid >= 0) r = mid; //要加等号,Chech条件
else l = mid + 1;
}
//if(r == nums.size() - 1) return ++r;
if(nums[r] - r == 0) return r;
return -1;
}
};