leetcode 448. Find All Numbers Disappeared in an Array(easy)
本来想天秀一把 直接用listcomp语句return
return [i for i in range(1,len(num)+1) if i not in nums]
然而超时哈哈哈。。。。:(。。。。
只能拆开写啦,set之后length会变所以先存一个变量
class Solution:
def findDisappearedNumbers(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
length = len(nums)
nums = set(nums)
return [i for i in range(1,length+1) if i not in nums]
Runtime: 252 ms, faster than 22.59% of Python3
(现在对运行时间淡定了,一来python本来就没有c/c++快,而来运行速度好像和网速有点关系,discussion里的解法自称很快的在我本地测也不咋快,so。。。找理由不看solution偷Or2)