Set Mismatch

Problem Id: 645 Difficulty: Easy


Intuition

Solution


class Solution:
    def findErrorNums(self, nums: List[int]) -> List[int]:
        s = set()
        missing = None
        twice = None
        for num in nums:
            if num in s:
                twice = num
            else:
                s.add(num)
        for i in range(1, len(nums) + 1):
            if i not in s:
                missing = i
                break
        return [twice, missing]