> For the complete documentation index, see [llms.txt](https://dfine.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dfine.gitbook.io/leetcode/448.find_all_numbers_disappeared_in_an_array.md).

# 448.Find All Numbers Disappeared in an Array

**448.Find All Numbers Disappeared in an Array**

难度:Easy

> 给定一个范围在 1 ≤ a\[i] ≤ n ( n = 数组大小 ) 的 整型数组，数组中的元素一些出现了两次，另一些只出现一次。

找到所有在 \[1, n] 范围之间没有出现在数组中的数字。

您能在不使用额外空间且时间复杂度为O(n)的情况下完成这个任务吗? 你可以假定返回的数组不算在额外空间内。

示例:

输入: \[4,3,2,7,8,2,3,1]

输出: \[5,6]

利用数组下标计算，当存在时将该索引值变为负数，这样不影响后面的索引判断。

```
class Solution {
public:
    vector<int> findDisappearedNumbers(vector<int>& nums) {
        vector<int >res;
        int tmp=-1;
        for(int i=0;i<nums.size();i++)
        {
            nums[abs(nums[i])-1]=-abs(nums[abs(nums[i])-1]);
        }
        for(int i=0;i<nums.size();i++)
            if(nums[i]>0) res.push_back(i+1);
        return res;
            
    }
};
```

> 执行用时 : 132 ms, 在Find All Numbers Disappeared in an Array的C++提交中击败了97.49% 的用户\
> 内存消耗 : 14.8 MB, 在Find All Numbers Disappeared in an Array的C++提交中击败了82.07% 的用户


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://dfine.gitbook.io/leetcode/448.find_all_numbers_disappeared_in_an_array.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
