18. Find the Highest number
Last updated
Last updated
class Solution {
public:
int findPeakElement(vector<int>& a)
{
int size=a.size();
int low=0, high=size-1;
while (low<=high)
{
int mid=(low+high)/2;
if (a[mid]>a[mid-1] && a[mid]>a[mid+1])
return a[mid];
else if (a[mid]>a[mid-1] && a[mid]<a[mid+1])
low=mid+1;
else high=mid-1;
}
return a[size-1];
}
};