<p>Given an integer array <code>nums</code> of length <code>n</code> where all the integers of <code>nums</code> are in the range <code>[1, n]</code> and each integer appears <strong>once</strong> or <strong>twice</strong>, return <em>an array of all the integers that appears <strong>twice</strong></em>.</p>

<p>You must write an algorithm that runs in <code>O(n)</code> time and uses only <em>constant</em> auxiliary space, excluding the space needed to store the output</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> nums = [4,3,2,7,8,2,3,1]
<strong>Output:</strong> [2,3]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong> [1]
</pre><p><strong class="example">Example 3:</strong></p>
<pre><strong>Input:</strong> nums = [1]
<strong>Output:</strong> []
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == nums.length</code></li>
	<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= n</code></li>
	<li>Each element in <code>nums</code> appears <strong>once</strong> or <strong>twice</strong>.</li>
</ul>

class Solution:
    def findDuplicates(self, nums: List[int]) -> List[int]:
        # Put number x at index = x-1. Set it to -1.
        # If x already there, -2
        # if nums[i] is already <0, then adv i.
        # Else:
        #  if nums[nums[i]] == -1, make it -2. Adv i  
        #  Else:
        #     j = nums[i]
        #     nums[i], nums[j] = nums[j], -1
        #     Dont move i
        # Finally count -2s.
        i = 0
        n = len(nums)
        print (nums)

        while i<n:
            if nums[i]<=0:
                i+=1
                continue
            j = nums[i]-1
            if nums[j] < 0:
                nums[j] -= 1
                nums[i] = 0
                i+=1
                continue
                 
            nums[i], nums[j] = nums[j], -1
            #print (nums)
        #c = sum([1 if x == -2 else 0 for x in nums])
        j = 0
        #print (nums)
        for i in range(n):
            if nums[i] == -2:
                nums[j] = i+1
                j+=1 
        return nums[:j]

22800