very aesy to understand in python,just less than 4 lines


  • 1
    Z

    #注意n是数组的size 而不是最大的数
    class Solution(object):

    def findDisappearedNumbers(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        # if not nums:return
        if nums == []: return []
        size = len(nums)
        all = range(1, size + 1)
        return list(set(all) - set(nums))
    

    s=Solution()
    print s.findDisappearedNumbers([4,3,2,7,8,2,3,1])

    >! >! >! Spoilerstrikethrough text


  • 0
    H

    @zixiaozhang Thank you for sharing,very clever idea.


Log in to reply
 

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