A simple C solution [Accepted]


  • 0
    B
    /**
     * Return an array of size *returnSize.
     * Note: The returned array must be malloced, assume caller calls free().
     */
    int* findErrorNums(int* nums, int numsSize, int* returnSize) {
        int a[10001]={0};
        int *result=(int*)malloc(sizeof(int)*2);
        *returnSize=2;
        for(int i=0;i<numsSize;i++)
        {
            if(++a[nums[i]]==2)
            {result[0]=nums[i];}           
        }
        for(int i=1;i<=numsSize;i++)
        {
            if(a[i]==0)
            {result[1]=i;return result;}
        }
        return result;
    }
    

Log in to reply
 

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