Array Partition I TLE?


  • 0
    T
    int arrayPairSum(int* nums, int numsSize) {
        if(numsSize==2)
            return nums[0]>nums[1]?nums[1]:nums[0];
        int max=nums[numsSize-1]>nums[numsSize-2]?nums[numsSize-1]:nums[numsSize-2];
        int min=nums[numsSize-1]<nums[numsSize-2]?nums[numsSize-1]:nums[numsSize-2];
        for(int i=0;i<numsSize-2;++i)
        {
            if(nums[i]>min)
            {
                int t=min;
                min=nums[i];
                nums[i]=t;
            }
            if(min>max)
            {
                int t=min;
                min=max;
                max=t;
            }
        }
        return min+arrayPairSum(nums, numsSize-2);
    }
    

    TLE?


Log in to reply
 

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