> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/bit/xor/268.-missing-number.md).

# 268. Missing Number

````java
```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
*/
```
````
