90. Missing Number

nums contains n distinct numbers from the range [0, n]. Return the one number missing from the range.

Example 1

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

Example 2

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

Sum formula: n(n+1)/2 − sum(nums).

Hint 2

Or XOR all indices and values: everything cancels except the missing number.

Bit ManipulationMath