Leetcode 分享筆記

448. Find All Numbers Disappeared in an Array
等級: Easy

原始題目連結請點此

leetcode

448. Find All Numbers Disappeared in an Array

class Solution(object):
    def findDisappearedNumbers(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        #算陣列長度
        #比對每一個庶子
        #比對到的話 把該樹籽移除
        #return 原本的陣列
        ans = []
        num_set = set(nums)
        for i in range(1,len(nums)+1):
            if i not in num_set:
                ans.append(i)
        return ans