Missing Number

The array nums holds n different numbers taken from 0, 1, 2, …, n. Exactly one number from that range is missing. Return it.

Constraints

  • 1 ≤ n (the length of nums) ≤ 20,000
  • The numbers are different and between 0 and n.

Example 1

Input
nums = [3,0,1]
Output
2
Why:

n is 3, so the range is 0 to 3, and 2 is not there.

Example 2

Input
nums = [0,1]
Output
2
Why:

n is 2; 0 and 1 are there, so 2 is missing.

Hints

    Was this a good challenge?

    Solved by
    0
    Submissions
    0
    Accepted
    –