更新时间:2023-02-26 16:42:07
这是 O(log n)的
算法存在。我们采用分而治之。
An O(log n)
algorithm exists. We use divide-and-conquer.
find_peak(lo,hi):
mid = (lo+hi)/2
if A[mid] >= A[mid-1], A[mid+1] return mid
if A[mid] < A[mid-1]
return find_peak(lo,mid-1) // a peak must exists in A[1..mid-1]
if A[mid] < A[mid+1]
return find_peak(mid+1,hi) // a peak must exists in A[mid+1..hi]