Python two pointer one loop


  • 0
    M
    class Solution:
        def findErrorNums(self, nums):
            """
            :type nums: List[int]
            :rtype: List[int]
            """
            nums.sort()
            dup = 0
            miss = 0
            tmp = 0
            for num in nums:
                if tmp == num:
                    dup = num
                if tmp == num - 2:
                    miss = num - 1
                tmp = num
            if miss == 0:
                miss = len(nums)
            return dup, miss
    

Log in to reply
 

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