[Leet Code] Find All Numbers Disappeared in an Array

Matthew Boyd
Sep 5, 2021

--

Leet Code: https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/

Problem:

Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.

Example 1:

Input: nums = [4,3,2,7,8,2,3,1]
Output: [5,6]

Example 2:

Input: nums = [1,1]
Output: [2]

Constraints:

  • n == nums.length
  • 1 <= n <= 105
  • 1 <= nums[i] <= n

Solution:

class Solution(object):
def findDisappearedNumbers(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
count = 0
# """[4,3,2,7,8,2,3,1]"""
solution = []
for i in range(len(nums)):
solution.append(i+1)

return set(solution) ^ set(nums)

--

--

Matthew Boyd
Matthew Boyd

Written by Matthew Boyd

Learning, and posting my findings!

No responses yet