Find Missing Number
Easy
Arrays
Array
Math
Bit Manipulation
Given an array containing n distinct numbers in range [0, n], find the missing number.
Constraints
1 ≤ n ≤ 10^4
Examples
Example 1:
Input: 3 0 1
Output: 2
Explanation: Range [0,3], missing 2
Example 2:
Input: 0 1
Output: 2
Hints
Sum formula: n*(n+1)/2 minus actual sum.
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console