用二分法解,注意mid的取值和left和right的关系
class Solution:
def findPeakElement(self , nums: List[int]) -> int:
# write code here
num_length = len(nums)
left = 0
right = num_length - 1
while left < right:
mid = int((left + right) / 2)
if nums[mid] < nums[mid + 1]:
left = mid + 1
else:
right = mid
return right