The following code ensures every *x* in *nums* is placed in index *i=x-1*. if in the final *nums* array, for some *i*, *nums[i]=0*, means *i+1* not in nums.

Although there a while loop nested in for loop, the total time complexity should only be O(n), since every *x* will get to the right index after only one operation.

```
public List<Integer> findDisappearedNumbers(int[] nums) {
int tmp = 0;
for (int i = 0; i < nums.length; i++) {
while (nums[i] != 0 && nums[i] != i + 1) {
tmp = nums[nums[i] - 1];
nums[nums[i] - 1] = nums[i];
if (tmp == nums[i])
nums[i] = 0;
else
nums[i] = tmp;
}
}
List<Integer> disappeared = new ArrayList<Integer>();
for (int i = 0; i < nums.length; i++) {
if (nums[i] == 0)
disappeared.add(i + 1);
}
return disappeared;
}
```