<p>Given an array <code>nums</code> of <code>n</code> integers where <code>nums[i]</code> is in the range <code>[1, n]</code>, return <em>an array of all the integers in the range</em> <code>[1, n]</code> <em>that do not appear in</em> <code>nums</code>.</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> [5,6]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> nums = [1,1]
<strong>Output:</strong> [2]
</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>
</ul>

<p>&nbsp;</p>
<p><strong>Follow up:</strong> Could you do it without extra space and in <code>O(n)</code> runtime? You may assume the returned list does not count as extra space.</p>

class Solution:
    def findDisappearedNumbers(self, nums):
        candicate = 'candidate'
        exist = 'exist'

        for i in range(len(nums)):
            nums[i] -= 1

        print(nums)
        

        v = nums[0]
        nums[0] = candicate

        stop_flag = False

        min_not_visited_idx = 0

        while not stop_flag:
            if min_not_visited_idx == v:
                min_not_visited_idx += 1

            if nums[v] in [candicate, exist]:
                nums[v] = exist
                v = None
            else:
                # if min_not_visited_idx == v:
                #     min_not_visited_idx += 1

                tmp = nums[v]
                nums[v] = exist
                v = tmp

        

            if v is None:
                if min_not_visited_idx == len(nums):
                        break
                while nums[min_not_visited_idx] in [candicate, exist]:
                    min_not_visited_idx += 1
                    if min_not_visited_idx == len(nums):
                        break

                if min_not_visited_idx == len(nums):
                        break
                tmp = nums[min_not_visited_idx]
                nums[min_not_visited_idx] = candicate
                v = tmp

                # if min_not_visited_idx == len(nums) - 1:
                #     stop_flag = True
                    
                # for idx, n in enumerate(nums):
                #     if n not in [candicate, exist]:
                #         v = n
                #         nums[idx] = candicate
                #         break
                #     elif idx == len(nums)-1:
                #         stop_flag = True

        disappeared = []
        for i,v in enumerate(nums):
            if v == candicate:
                disappeared.append(i+1)

        return disappeared
22600