二分搜索
class Solution:
def findPeakElement(self, nums: List[int]) -> int:
l, r = 0, len(nums)
while l < r:
m = (l + r) >> 1
if (m == len(nums) - 1 or nums[m] > nums[m + 1]) and (m == 0 or nums[m] > nums[m - 1]):
return m
if m != len(nums) - 1 and nums[m] <= nums[m + 1]:
l = m
continue
r = m
return l