645. Set Mismatch

Information

  • Diffculty: Easy

  • Created: 2019-09-01 23:57:19

  • Last Motified: 2019-09-01 23:57:19

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]