[LeetCode]41 缺失的第一个正数

题目描述

给定一个未排序的整数数组,找出其中没有出现的最小的正整数。

示例1:

输入: [1,2,0]
输出: 3

示例2:

输入: [3,4,-1,1]
输出: 2

示例3:

输入: [7,8,9,11,12]
输出: 1

代码

1
2
3
4
5
6
7
8
9
10
11
class Solution:
def firstMissingPositive(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
t=set(range(1,len(nums)+2))
for i in nums:
if i in t:
t.remove(i)
return min(t)