题目链接:https://leetcode-cn.com/problems/peak-index-in-a-mountain-array/
题目如下:
class Solution {
public:
int peakIndexInMountainArray(vector<int>& arr) {
int low=0,high=arr.size()-1;
while(low<=high){
int mid=low+(high-low)/2;
if(mid==0) low=mid+1;//最小
else if(mid==arr.size()-1) high=mid-1;//最大
else if(arr[mid-1]<arr[mid]&&arr[mid]>arr[mid+1]) return mid;//居中位置
else if(arr[mid-1]>arr[mid]) high=mid-1;//下降边
else low=mid+1;//上升边
}
return -1;
}
};