二分查找(C++实现)
class Solution {
public:
int peakIndexInMountainArray(vector<int>& arr) {
int n = arr.size();
if(n==0)
{
return -1;
}
int left = 0;
int right = n-1;
while(left<right)
{
int mid = left + (right-left)/2;
if(arr[mid]<arr[mid+1])
{
left = mid + 1;
}
else{
right = mid;
}
}
return left;
}
};