Python3 solution

Algo:

convert the list into a set(finding an element in set is O(1)) iterate from 1 to (1+"length of nums"+1) and first number we can't find is the answerWhy (1+"length of nums"+1):

we are to find first missing positive number(which start from 1) if "nums" start with 1: maximum value it can go to is 1+"length of nums" all other cases, we will for sure find missing number before: 1+"length of nums" value class Solution: def firstMissingPositive(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums) == 0: return 1 nums = set(nums) for i in range(1, 1+len(nums)+1): if i not in nums: return i