---
# System prepended metadata

title: 0268. Missing Number
tags: [Leetcode, Easy]

---

# 0268. Missing Number
###### tags: `Leetcode` `Easy`
Link: https://leetcode.com/problems/missing-number/
## 思路
异或运算可以消除重复的值，因为将0~n做一次异或运算，再跟nums里面的值做异或运算，结果即是答案
## Code
```java=
class Solution {
    public int missingNumber(int[] nums) {
        int res = nums.length;
        for(int i = 0;i < nums.length;i++){
            res ^= i;
            res ^= nums[i];
        }
        return res;
    }
}
```