Given an unsorted integer array, find the smallest missing positive integer.
Example
1 2 3 4 5
Input: [1,2,0] Output: 3
Input: [3,4,-1,1] Output: 2
Solution
Actually, this approach is quite tricky to me. We have to maintain the sequence like index0 -> 1, index1 -> 2, etc, when we see the element didn’t meet the requirement we have to swap until we cannot move or meet the requirement. nums[i] should be nums[i] - 1(index) position.