- class Solution:
- def findDisappearedNumbers(self, nums) -> int:
- a=set(nums)
- b=len(nums)
- c=[]
- while b>0:
- if b not in a:
- c.append(b)
- b-=1
- else:
- b=b-1
- return c
执行用时 :536 ms, 在所有 Python3 提交中击败了 59.58% 的用户
内存消耗 :23.5 MB, 在所有 Python3 提交中击败了 11.39% 的用户
执行用时为 148 ms 的范例
- class Solution:
- def findDisappearedNumbers(self, nums: List[int]) -> List[int]:
- nums_set = set(nums)
- ret = []
- for i in range(1,len(nums) + 1):
- if i not in nums_set:
- ret.append(i)
- return ret
执行用时 :448 ms, 在所有 Python3 提交中击败了 79.58% 的用户
内存消耗 :23.8 MB, 在所有 Python3 提交中击败了 5.06% 的用户
[不知道为啥用时不同]
思路相同...
--2019.10.9
来源: http://www.bubuko.com/infodetail-3232645.html