1
is present in the array. If not, return 1
as the answer.n
by 1
s.a
in the array, negate the value at index abs(a) - 1
if it is positive, to mark a
as present. Use index 0
to record the presence of n
.1
. The first index with a positive value indicates the smallest missing positive integer.1
to n - 1
are negative, check the value at index 0
. If it's positive, return n
, otherwise return n + 1
.