Python
from time import sleep
class Solution:
# @param A, a list of integers
# @return an integer
def firstMissingPositive(self, A):
# write your code here
if len(A) == 0:
return 1
m = 0
n = len(A)
while m < n:
if A[m] == m + 1:
m += 1
else:
if A[m] >= 0 and A[m] < n and A[m] != A[A[m] - 1]:
#A[m], A[A[m] - 1] = A[A[m] - 1], A[m]
A[A[m] - 1], A[m] = A[m] ,A[A[m] - 1]
else:
m += 1
for i in range(n):
if A[i] != i + 1:
return i + 1
return n + 1