https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/

Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.

Find all the elements of [1, n] inclusive that do not appear in this array.

Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.

#### java

https://discuss.leetcode.com/topic/65738/java-accepted-simple-solution

Java accepted simple solution

The basic idea is that we iterate through the input array and mark elements as negative using nums[nums[i] -1] = -nums[nums[i]-1]. In this way all the numbers that we have seen will be marked as negative. In the second iteration, if a value is not marked as negative, it implies we have never seen that index before, so just add it to the return list.

https://discuss.leetcode.com/topic/66063/5-line-java-easy-understanding

5-line Java Easy-understanding

https://discuss.leetcode.com/topic/66211/2ms-o-n-in-space-java

2ms O(n) In-Space Java

Think we surely have to negate anytime we are given an array with values from 1 to the length of array. If anyone has a better idea, will be happy to hear.

The steps followed in this is:

1. Negate each number while traversing
2. Run again and find the index that is not negated.

https://discuss.leetcode.com/topic/66581/simple-java-in-place-sort-solution

Simple Java In-place sort solution

The idea is simple, if nums[i] != i + 1 and nums[i] != nums[nums[i] - 1], then we swap nums[i] with nums[nums[i] - 1], for example, nums[0] = 4 and nums[3] = 7, then we swap nums[0] with nums[3]. So In the end the array will be sorted and if nums[i] != i + 1, then i + 1 is missing.

Since every swap we put at least one number to its correct position, the time is O(n)

#### cpp

https://discuss.leetcode.com/topic/65944/c-solution-o-1-space

c++ solution O(1) space

The idea is very similar to problem 442. Find All Duplicates in an Array: https://leetcode.com/problems/find-all-duplicates-in-an-array/.

First iteration to negate values at position whose equal to values appear in array. Second iteration to collect all position whose value is positive, which are the missing values. Complexity is O(n) Time and O(1) space.

#### python

https://discuss.leetcode.com/topic/68838/python-4-lines-with-short-explanation

Python 4 lines with short explanation

For each number i in nums,

we mark the number that i points as negative.

Then we filter the list, get all the indexes

who points to a positive number.

Since those indexes are not visited.

https://discuss.leetcode.com/topic/68430/python-one-liner

Python One-liner