O(n) Java


  • 1
    J
    public int findPeakElement(int[] nums) {
            int index = 0;
            int max = nums[0];
            for(int i = 1; i < nums.length; i++){
                if(max < nums[i]){
                    max = nums[i];
                    index = i;
                }
            }
            return index;
        }

Log in to reply
 

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