01. Peak element
My Approach
Time and Auxiliary Space Complexity
Code (C++)
class Solution {
public:
int peakElement(int arr[], int n) {
int left = 0, right = n - 1, mid;
while (left < right) {
mid = (left + right) / 2;
if (arr[mid] < arr[mid + 1])
left = mid + 1;
else
right = mid;
}
return left;
}
};Contribution and Support
Last updated