二分法求先单调增然后单调减的数列的最大值下标
1 #852
2 #Runtime: 537 ms (Beats 55.42%)
3 #Memory: 25.7 MB (Beats 90.39%)
4
5 class Solution(object):
6 def peakIndexInMountainArray(self, arr):
7 """
8 :type arr: List[int]
9 :rtype: int
10 """
11 l, r = 0, len(arr) - 1
12 while l < r:
13 mid = (l + r) // 2
14 if arr[mid] < arr[mid + 1]:
15 l = mid + 1
16 else:
17 r = mid
18 return r