Loading...
You are given an unsorted array of integers nums.
nums
Return the smallest positive integer that does not appear in nums. The positive integers are 1, 2, 3 and so on.
1
2
3
You must write an algorithm that runs in O(n) time and uses constant extra space.
O(n)
Input: nums = [1, 2, 0] Output: 3 Explanation: Both 1 and 2 appear, and 3 does not.
Input: nums = [3, 4, -1, 1] Output: 2 Explanation: 1 appears but 2 does not, so 2 is the smallest positive integer missing.
Input: nums = [7, 8, 9, 11, 12] Output: 1 Explanation: Nothing in the array equals 1, so the answer is the smallest positive integer of all.
nums.length
nums[i]