C solution log(n) recursive


  • 0
    C
    int findLocalMax(int* nums, int numsSize, int start, int end)
    {
        int mid1 = (start + end)/2;
        int mid2 = mid1+1;
        
        if (start == end)
        {
            return start;
        }
        
        if (nums[mid1] < nums[mid2])
        {
            return findLocalMax(nums, numsSize-(mid2-start), mid2, end);
        }
        else
        {
            return findLocalMax(nums, numsSize-(end-mid1), start, mid1);
        }
    }
    
    int findPeakElement(int* nums, int numsSize) {
        
        return findLocalMax(nums, numsSize, 0, numsSize-1);
    }

Log in to reply
 

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