class Solution {
public:
int getNumberSameAsIndex(vector<int>& nums) {
int n = nums.size();
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[l] != l) return -1;
return l;
}
};
class Solution {
public:
int getNumberSameAsIndex(vector<int>& nums) {
int n = nums.size();
int l = 0, r = nums.size() - 1;
while (l < r) {
int mid = l + r + 1 >> 1;
if (nums[mid] <= mid) l = mid;
else r = mid - 1;
}
if (nums[l] != l) return -1;
return l;
}
};