首页 > 编程语言 > 详细

leetcode——448.找到所有数组中消失的数字

时间:2019-10-09 20:00:17      阅读:106      评论:0      收藏:0      [点我收藏+]
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
 
 

leetcode——448.找到所有数组中消失的数字

原文:https://www.cnblogs.com/taoyuxin/p/11643959.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!