classSolution:defpeakIndexInMountainArray(self,A: List[int]) ->int: n =len(A) i =0while i+1< n and A[i]< A[i+1]: i +=1return i
解法二:二分
classSolution:defpeakIndexInMountainArray(self,arr) ->int: n =len(arr) l =0 r = n -1while l <= r: mid = l + (r - l) //2#找山顶,则遇到上坡就右移,遇到下坡就左移if arr[mid -1]< arr[mid]< arr[mid +1]: l = mid +1elif arr[mid -1]> arr[mid]> arr[mid +1]: r = mid -1else:return midreturn l