📅  最后修改于: 2023-12-03 15:23:04.699000             🧑  作者: Mango
给定一个长度为 n
的非空数组 A
,其中元素按照升序排序,找出一个 i
,使得:
0 <= i < n
A[i] == i
def find_fixed_point(arr: List[int]) -> int:
pass
n
的非空数组arr
,arr[0] <= arr[1] <= ... <= arr[n-1]
。i
;如果找不到,则返回-1
。arr = [-10, -5, 0, 3, 7]
assert find_fixed_point(arr) == 3
arr = [0, 2, 5, 8, 17]
assert find_fixed_point(arr) == 0
arr = [-10, -5, 3, 4, 7, 9]
assert find_fixed_point(arr) == -1