class Solution:
def findDisappearedNumbers(self, nums: List[int]) -> List[int]:
""" O(N)/O(1)
two loops
1. iterate throught each num, mark nums[num-1] as negtive
2. loop through the array, the positions where numbers are positive is the missing numbers
instead of using negtive sign to mark numbers at position i already existed, can use +N as offset and check if nums[i] < N
"""
res = []
n = len(nums)
for i in range(n):
x = abs(nums[i])-1
nums[x] = -1 * abs(nums[x])# here need to multiply by abs value of nums[x], else original negtive value will be cancel out to positive
for i in range(n):
if nums[i] > 0:
res.append(i+1)
return res