class Solution {
public:
int peakIndexInMountainArray(vector<int>& arr) {
int st=0, end=arr.size()-1;
int mid=st+(end-st)/2;
while(st<=end)
{
if(arr[mid]>arr[mid-1]&&arr[mid]>arr[mid+1]) return mid;
if(arr[mid]<arr[mid+1]) st=mid+1;
else if(arr[mid]<arr[mid-1]) end=mid;
mid=st+(end-st)/2;
}
return mid;
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter