268. Missing Number

```java
class Solution {
    public int missingNumber(int[] nums) {
        int n = nums.length;
        int result = 0;
        result ^= n;
        for (int i = 0; i < n; i++) {
            result ^= i ^ nums[i];
        }
        return result;
    }
}
/*
T: O(n)
S: O(1)
[3,0,1]

0 1 2 3 idx
0 1   3

n = 3 -> can be the extra idx

so xor extra idx first

then xor idx and nums[i] to find missing number
*/
```

Last updated