1064 Fixed Point
Given an array A
of distinct integers sorted in ascending order, return the smallest index i
that satisfies A[i] == i
. Return -1
if no such i
exists.
Example 1:
Example 2:
Example 3:
Note:
1 <= A.length < 10^4
-10^9 <= A[i] <= 10^9
这题经典二分,不过注意要找的是smallest,所以相等的时候不能立刻返回。要end = mid,继续向前面找。
Last updated
Was this helpful?