编程语言
首页 > 编程语言> > leetcode-python-缺失数字

leetcode-python-缺失数字

作者:互联网

1)获取未缺失数字的列表,逐个对比(很慢!)

class Solution:
    def missingNumber(self, nums: List[int]) -> int:
        reallist = [i for i in range(len(nums)+1)]
        for i in reallist:
            if i not in nums:
                return i

2)求和问题

class Solution:
    def missingNumber(self, nums: List[int]) -> int:
        return sum([i for i in range(len(nums)+1)])-sum(nums)

 

标签:reallist,missingNumber,nums,python,self,缺失,int,return,leetcode
来源: https://www.cnblogs.com/cbachen/p/14878418.html