Simple solution in c, 3ms


  • 1
    Y
    int findPeakElement(int num[], int n) {
    int *tmp, i;
    tmp = (int*)malloc(sizeof(int) * (n-1));
    for(i = 0; i < n-1; ++i)tmp[i] = num[i+1] - num[i];
    for(i = 0; tmp[i] > 0 && i < n-1; ++i);
    return i;
    

    }


  • 0
    V

    Logic is correct but does it give answer in O(log n) time ? Also , we need to use constant space ..


Log in to reply
 

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