寻找峰值
https://www.lintcode.com/problem/75/description?utm_source=sc-libao-ql
A = [1, 2, 1, 3, 4, 5, 7, 6]1Last updated
https://www.lintcode.com/problem/75/description?utm_source=sc-libao-ql
A = [1, 2, 1, 3, 4, 5, 7, 6]1Last updated
A = [1,2,3,4,1]3from typing import (
List,
)
class Solution:
"""
@param a: An integers array.
@return: return any of peek positions.
"""
def find_peak(self, a: List[int]) -> int:
# write your code here
start, end = 0, len(a) - 1
while start + 1 < end:
mid = (start + end) // 2
if a[mid-1] < a[mid] > a[mid+1]:
return mid
elif a[mid] < a[mid + 1]:
start = mid
else:
end = mid