Table of Content
题目如下:
解题思路:
题目要求时间复杂度为O(n), 如果是对数组进行排序再查找,很难获得比较好的效率。通过Python的 not in 判断,可以更快的发现缺失目标。
##参考代码:
1 2 3 4 5 6 7 8 9 10 |
class Solution: def firstMissingPositive(self, nums): """ :type nums: List[int] :rtype: int """ for i in range(1, len(nums) + 2): # be careful the start and end if i not in nums: return i |