Share my c++ solution, 3 lines, 8ms

  • 0
    int findPeakElement(vector<int>& nums) {
        for(int i=1; i<nums.size(); i++)
            if(nums[i] < nums[i-1]) return i-1;
        return nums.size()-1;

  • 0

    If you take a look at the hint you will see they ask for a O(log(n)) solution...

Log in to reply

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