Solution in C


  • 0
    L
    int* findDisappearedNumbers(int* nums, int numsSize, int* returnSize) {
        int m;
        for (int c = 0; c < numsSize; c++) {
            m = abs(nums[c]) - 1;
            nums[m] = -1 * abs(nums[m]);
        }
    
        *returnSize = 0;
        for (int c = 0; c < numsSize; c++)
            if (nums[c] > 0)
                (*returnSize)++;
        
        int *ret = (int *) calloc (*returnSize, sizeof (int));
        int s = 0;
        for (int c = 0; c < numsSize; c++)
            if (nums[c] > 0)
                ret[s++] = c + 1;
        
        return ret;
    }
    

Log in to reply
 

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