class Solution(object):
def findDisappearedNumbers(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
return[i
for i
in range(
1,len(nums)+
1)
if i
not in nums]
这种情况是超时的
利用set的集合(差集)性质,因为最后要返回的是list,使用list()转换 U=set(range(1,len(nums)+1))
U =
set(range(
1,
len(nums)+
1))
A =
set(nums)
B = U - A
return list(B)