小米日常实习

原题链接:
https://leetcode.cn/problems/peak-index-in-a-mountain-array/description/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public int peakIndexInMountainArray(int[] arr) {
int l = -1, r = arr.length;
int n = arr.length;
while(l + 1 < r){
int mid = l + r >> 1;
if(mid + 1 < n && arr[mid] > arr[mid + 1]){
r = mid;
}else{
l = mid;
}
}

return r;
}
}