1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| class Solution { public int peakIndexInMountainArray(int[] arr) { int i = 0; int j = arr.length - 1;
while(true){ int mid = (i + j)/2; if(arr[mid] > arr[mid-1] && arr[mid] > arr[mid+1]){ return mid; }else if(arr[mid]>arr[mid-1]){ i = mid; }else if(arr[mid]<arr[mid-1]){ j = mid; } } } }
|