LeetCode 448 – Python 3 (Week 4 – 02)

Solution 1

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

Time complexity is O(n). Space complexity is O(1).

Leave a comment

Design a site like this with WordPress.com
Get started