```
class Solution:
# @param {integer[]} nums
# @return {integer}
def firstMissingPositive(self, nums):
if not nums:
return 1
for i in range(0, len(nums)):
j = i
while nums[j] > 0 and nums[j] <= len(nums) and nums[j] != j + 1 and nums[j] != nums[nums[j] - 1]:
t = nums[j] - 1
nums[j], nums[t] = nums[t], nums[j]
for i in range(0, len(nums)):
if nums[i] != i + 1:
return i + 1
return len(nums) + 1
```