Leetcode 645 Solution

This article provides solution to leetcode question 645 (set-mismatch)

https://leetcode.com/problems/set-mismatch

Solution

class Solution:
    def findErrorNums(self, nums: List[int]) -> List[int]:
        m = collections.defaultdict(int)
        for n in nums:
            m[n] += 1
        dup_ele = None
        miss_ele = None
        for i in range(1, len(nums) + 1):
            if m[i] == 0:
                miss_ele = i
            elif m[i] == 2:
                dup_ele = i
        return [dup_ele, miss_ele]