Posted on

Description

Submission

class Solution {
public:
    int peakIndexInMountainArray(vector<int>& arr) {
        int left = 0, right = arr.size();

        while(left < right) {
            int mid = (right - left) / 2 + left;

            if(mid == 0) return 0;
            
            if(arr[mid-1] < arr[mid]) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }

        return left-1;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *