Simple python solution


  • 1
    S
    class Solution(object):
        def findErrorNums(self, nums):
            """
            :type nums: List[int]
            :rtype: List[int]
            """
            ans = []
            if nums:
                s = set()
                for x in nums:
                    if x in s:
                        ans.append(x)
                    s.add(x)
                n = len(nums)
                
                ans.append( sum(range(1,n+1)) - sum(s) )
                
            return ans

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.