Runtime Error


  • 0
    U

    can you tell me Why my C code cannot pass?

    int choose(int* nums, int index, int target, int numsSize, int count)
    {
    if (index == numsSize - 1)
    return count;
    else
    {
    if (nums[index + 1] < target)
    {
    count++;
    }
    return choose(nums, index + 1, target, numsSize, count);
    }
    }
    int* countSmaller(int* nums, int numsSize, int* returnSize) {
    returnSize = (int *)malloc(sizeof(int)*numsSize);
    if (!nums || numsSize == 0)
    return returnSize;
    else if (numsSize == 1)
    {
    returnSize[0] = 0;
    return returnSize;
    }
    for (int i = 0; i < numsSize; i++)
    {
    int count = 0;
    returnSize[i] = choose(nums, i, nums[i], numsSize, count);
    }
    return returnSize;
    }


  • 0
    P

    You should know that nums may be empty.


Log in to reply
 

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