leetcode——41. 缺失的第一个正数

class Solution(object):
    def firstMissingPositive(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if nums==[]:
            return 1
        for i in nums:
            if i<=0:
                nums.remove(i)
        if nums==[]:
            return 1
        for i in range(1,len(nums)+1):
            if i not in nums:
                return i
        return len(nums)+1
执行用时 :24 ms, 在所有 python 提交中击败了90.19%的用户
内存消耗 :11.8 MB, 在所有 python 提交中击败了26.09%的用户
                                                                                                             ——2019.10.14

猜你喜欢

转载自www.cnblogs.com/taoyuxin/p/11670778.html