My 0ms solutions in C


  • 0
    Q
    int findPeakElement(int* nums, int numsSize) {
        int flag=1;
        int i;
        if (nums==NULL || numsSize==0)
            return -1;
        for (i=1; i<numsSize; i++) {
            if (flag&&nums[i]<nums[i-1])
                return i-1;
            flag=(nums[i]>nums[i-1]);
        }
        if (flag) return numsSize-1;
        return -1;
    }

  • 0
    P

    it's naive! O(n) solution is too simple, we need O(log(n))!


Log in to reply
 

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