Find All Numbers Disappeared in an Array

Problem Id: 448 Difficulty: Easy


Intuition

Solution


class Solution:
    def findDisappearedNumbers(self, nums: List[int]) -> List[int]:
        for num in nums:
            num = abs(num)
            nums[num - 1] = -abs(nums[num - 1])
        ans = []
        for i in range(len(nums)):
            if nums[i] > 0:
                ans.append(i + 1)
        return ans