Back to ArraysMissing Number
Easy

Missing Number

EasyRecommendedIndex MappingHashing

Given an array containing n distinct numbers taken from the range 0 to n, find the one number in that range that's missing from the array.

Examples

Example 1

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

Explanation: n = 3, so the full range is [0,1,2,3]; only 2 is missing from the array.

Example 2

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

Example 3

Input:
nums = [9,6,4,2,3,5,7,0,1]
Output:
8

Constraints

  • n == nums.length
  • 1 <= n <= 10^4
  • 0 <= nums[i] <= n
  • All the numbers of nums are unique.

Loading editor…

Code execution is coming soon.