# 268.Missing Number

**268.Missing Number**

难度:Easy

> 给定一个包含 0, 1, 2, ..., n 中 n 个数的序列，找出 0 .. n 中没有出现在序列中的那个数。

```
示例 1:

输入: [3,0,1]
输出: 2
示例 2:

输入: [9,6,4,2,3,5,7,0,1]
输出: 8
```

说明: 你的算法应具有线性时间复杂度。你能否仅使用额外常数空间来实现?

直接异或即可。

```
class Solution {
public:
    int missingNumber(vector<int>& nums) {
        int temp=0;
        for(int i=1;i<=nums.size();i++)
            temp ^=i^nums[i-1];
        return temp;
    }
};
```

> 执行用时 : 28 ms, 在Missing Number的C++提交中击败了93.78% 的用户\
> 内存消耗 : 9.9 MB, 在Missing Number的C++提交中击败了17.85% 的用户


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dfine.gitbook.io/leetcode/268.missing_number.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
