class Solution {
public:
int getNumberSameAsIndex(vector<int>& nums) {
//依据数列性质找nums[i] - i == 0的数值即为所求,因为左边nums[i] - i <=0,右边大于0
//注意chech函数中等号成立的条件有没有等号哦
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;
else l = mid + 1;
}
if(nums[r] == r) return r;
return -1;
}
};