所有Leetcode题目不定期汇总在 Github, 欢迎大家批评指正,讨论交流。
class Solution:
def findDisappearedNumbers(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
# method one 集合操作
return list(set(range(1, len(nums)+1)) - set(nums))
# method two
# s = set(nums) # 不能直接写成一行,效率太低
# return [i for i in range(1, len(nums)+1) if i not in s]
所有Leetcode题目不定期汇总在 Github, 欢迎大家批评指正,讨论交流。