📜  山数组 leetcode - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:17.693000             🧑  作者: Mango

代码示例2
class Solution {    
    public static int peakIndexInMountainArray(int[] arr) {
        int start = 0;
        int end = arr.length-1;

        while(start < end){
            int mid = start + (end-start)/2;

            if (arr[mid] > arr[mid+1]) end = mid;
            else start = mid+1;
        }
        return start;
    }
}