Neat python solution using set operation


  • 0
    D
    class Solution:
        def findErrorNums(self, nums):
            x = set(range(1, len(nums) + 1)) - set(nums)
            nums.sort()
            for i in range(1, len(nums)):
                if nums[i] == nums[i - 1]:
                    return [nums[i]] + list(x)
    

Log in to reply
 

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