So [0] should return 1 and [1] should return 0? this makes no sense

  • -1

    When I ran my test I failed because [0] didn't return 1 so I updated my code to increment the value by 1 and return it if only 1 element is in the array. Then I submit and it says [1] should return 0 instead of 2...

  • 0

    See, it is an array that starts at 0, and has n elements, and there's always one element missing, so the complete array should have n+1 element.
    Therefore input [0], one element missing, it must be 1, but if you input [1], the array should start at 0 but there is no 0, so 0 must be the missing element.
    Does this make sense?

Log in to reply

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