JavaScript solution


  • 0
    M
    var findPeakElement = function(nums) {
        const peak = {
            index: 0,
            value: nums[0]
        };
    
        for (let i = 1; i < nums.length; i++) {
            if (nums[i] > peak.value) {
                peak.index = i;
                peak.value = nums[i];
            }
        }
        return peak.index;
    };
    

Log in to reply
 

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