---
# System prepended metadata

title: LeetCode 448. Find All Numbers Disappeared in an Array

---

# LeetCode 448. Find All Numbers Disappeared in an Array
[LeetCode 448. Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/) (<font color=#00AF9B>Easy</font> 61.2%) 

<!-- 
(<font color=#00AF9B>Easy</font> 53.8%) 
(<font color=#FFB800>Medium</font> 39.6%)
(<font color=#FF375F>Hard</font>)
 -->
    
- 限制 :

    <ul>
    <li><code>n == nums.length</code></li>
    <li><code>1 <= n <= 10^5</code></li>
    <li><code>1 <= nums[i] <= n</code></li>
    </ul>

- Solution
    這題要找的是沒有在數列裡面的數是哪些。
    先從頭到尾看數列裡面有哪些數，並且將有在數列裏頭的數字標記。最後再把沒有被標記的數字一一填到要回傳的數列裡面。
    - 時間複雜度: $O(n)$
    - 空間複雜度: $O(n)$

- 程式碼
    ```c++=
    class Solution {
    public:
        vector<int> findDisappearedNumbers(vector<int>& nums) {
            vector<bool> record(nums.size(), 0);
            for (auto& num : nums) {
                record[num - 1] = true;
            }

            vector<int> result;
            for (int i = 0; i < record.size(); i++) {
                if (!record[i])
                    result.push_back(i + 1);
            }
            return result;
        }
    };
    ```
</details>