My C answer to this question, NOT THE MATH answer!


  • 0
    B

    In this question ,we can sort them first and find the missing number very easily!!!

    #include <stdio.h>
    #include <stdlib.h>

    int cmp(const void *a,const void b)
    {
    return(
    (int )a-(int *)b);
    }

    int missingNumber(int* nums, int numsSize) {
    qsort(nums,numsSize,sizeof(nums[0]),cmp);
    for(int i=0; i<numsSize;i++)
    {
    if(nums[i]!=i)
    {
    return i;
    }
    }
    }


Log in to reply
 

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