90. Missing Number

Easy · Math

Given an array containing n distinct numbers taken from the range [0, n], find the missing number. The array is a permutation of numbers from 0 to n with exactly one number missing.

For example, if n=3, the array should contain three numbers from [0, 1, 2, 3], but one is missing.

Examples

Example 1
Input: [3, 0, 1]
Output: 2
Explanation: The array has 3 elements. The range is [0, 1, 2, 3]. The numbers 0, 1, 3 are present, so 2 is missing.
Example 2
Input: [0, 1]
Output: 2
Explanation: The array has 2 elements. The range is [0, 1, 2]. The numbers 0, 1 are present, so 2 is missing.

Constraints