Easy understand Javascript solution


  • 0
    N

    var findPeakElement = function(nums) {
    if(nums.length===1) {
    return 0;
    }

    var i = 1;
    while (i<nums.length) {
        if(nums[i-1]<nums[i]) {
            i+=1;
        } else {
            return (i-1);
        }
    }
    return nums.length-1;
    

    };


Log in to reply
 

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