Question
Given an arrayÂ
nums
 containingÂn
 distinct numbers in the rangeÂ[0, n]
, return the only number in the range that is missing from the array.
This is abit_manip question.
Idea
- XOR solution
- Using the principle of XORs (XOR with 0 returns the same number, XOR with the same number returns 0, XOR with two different numbers do nothing)
- Using this logic, if we XOR all the numbers in an array together, and then xor that with every number in a given range, all the duplicate numbers will cancel out and the number not in the range will be the one remaining