美文网首页
2020-03-13 Day 20: Leetcode 41.

2020-03-13 Day 20: Leetcode 41.

作者: YueTan | 来源:发表于2020-03-13 08:05 被阅读0次
    class Solution:
        def firstMissingPositive(self, nums: List[int]) -> int:
            maxpos=0
            for num in nums:
                if num>maxpos:
                    maxpos=num
            minpos=maxpos
            for num in nums:
                if num<minpos and num>0:
                    minpos=num
            
            if minpos>1:
                return 1
            for i in range(minpos+1,maxpos+1):
                if i in nums:
                    continue
                else:
                    return i
            return maxpos+1
    

    相关文章

      网友评论

          本文标题:2020-03-13 Day 20: Leetcode 41.

          本文链接:https://www.haomeiwen.com/subject/dkffshtx.html