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