← 返回 oracle 的题目列表Missing Number
类型:online_judge
Coding Question: Missing Number
Given an array nums containing n distinct numbers from the range [0, n], there are n + 1 possible numbers in the range but only n numbers in the array. Therefore, exactly one number is missing.
Find the missing number.
Input Format
The first line contains an integer n, the length of the array.
The second line contains n distinct integers representing nums.
Output Format
Print one integer, the missing number.
Constraints
0 <= n <= 10^5
nums.length == n
0 <= nums[i] <= n
All numbers in nums are distinct.
Example 1
Input:
3
3 0 1
Output:
2
Example 2
Input:
2
0 1
Output:
2
Example 3
Input:
9
9 6 4 2 3 5 7 0 1
Output:
8
Example
Input
3
3 0 1
Output
2