这个我自己花了2分钟写了一个Python版本,Time Limit Exceeded,QAQ~~~可以跳过这段了~~~
class Solution(object):
def firstMissingPositive(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
i=1
while(True):
for j in nums:
if j==i:
i+=1
break
elif j==nums[-1]:
return i
正确版本:
Key:这个最小遗漏正整数的范围一定是在1~len(nums)+1之间,注意是+1,+1,+1!!!。(我自己写出来的,激动得想哭~~~)
class Solution(object):
def firstMissingPositive(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n=len(nums)
if n==0:
return 1
for i in range(1,len(nums)+2):
for j in range(len(nums)):
if nums[j]==i:
break
elif j==len(nums)-1:
return i