My 0ms Solution in C


  • -1
    R

    int findPeakElement(int* nums, int numsSize) {

    if(numsSize==1)
    return 0;
    if(numsSize==2){
        if(nums[0]>nums[1])
        return 0;
        else
        return 1;
    }
    
    int i,j,k;
    for(i=0;i<=numsSize-1;i++){
        j=i+1;
        k=i-1;
        if(nums[i]>nums[j] && nums[i]>nums[k]){
            return i;
        }
    }
    

    }


  • 0
    M

    Your solution takes O(n) time. However, the problem solution should be O(logn).


Log in to reply
 

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