c solution


  • 0
    S

    int* findDuplicates(int* nums, int numsSize, int* returnSize) {
    if(nums==NULL||numsSize<2)
    {
    *returnSize=0;
    return NULL;
    }
    returnSize=0;
    int result=(int)malloc(sizeof(int)
    (numsSize/2));
    for(int i=0;i<numsSize;i++)
    {
    int num=abs(nums[i]);
    if(nums[num-1]>0)
    nums[num-1]=-nums[num-1];
    else
    result[(*returnSize)++]=num;
    }
    return result;
    }


Log in to reply
 

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