class Solution(object):
def getNumberSameAsIndex(self, nums):
l=0
r=len(nums)-1
while(l<=r):
mid=l+r+1>>1
if nums[mid]==mid:
return mid
if nums[mid]<mid:
l=mid+1
else:
r=mid-1
else:
return -1
注意下标,r的边界是长度-1