Straightforward C++ solution


  • 0
    Y
    class Solution {
    public:
        int findPeakElement(vector<int>& nums) {
            int low(0),high(nums.size()-1);
            while(low<high){
                int mid = low + (high-low)/2;
                if( nums[mid] < nums[mid + 1]){
                    low = mid + 1;
                } else {
                    high = mid;
                }
            }
            return low;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.