nums holds n distinct numbers from the range [0, n]. Return the only number in that range that is missing.
XOR all indices 0..n and all values. Every present number cancels with its index (x ^ x = 0), leaving only the missing one.
1function missingNumber(nums: number[]): number {2let x = nums.length;3for (let i = 0; i < nums.length; i++) {4x ^= i ^ nums[i];5}6return x;7}
Start with n = 3 (the index that has no slot).
Space: play/pause · ←/→: step