What if I have an array like [1,2,3,4]?


  • -1
    M

    the miss number can be 0 or 5.


  • 0
    Y

    the length of the array is 4, so the missing number from 0 to 4 is 0


  • 0
    M

    the problem doesn't say the array is come from 0


  • 0

    The question says

    Given an array containing n distinct numbers taken from 0, 1, 2, ...,
    n, find the one that is missing from the array.

    For example, Given nums = [0, 1, 3] return 2.

    So similarly it means if array is of size 4 , it can have numbers from the set 0 , 1, 2 , 3 , 4

    In array of length 4 , you have [1,2,3,4] .. So here , missing number from the set is 0 .

    Hence, the answer is 0 regardless of whether it can be inserted in the array or not.


Log in to reply
 

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