leetcode 41 缺失的第一个正数

Given an unsorted integer array, find the smallest missing positive integer.
Example 1:
1 | Input: [1,2,0] |
Example 2:
1 | Input: [3,4,-1,1] |
Example 3:
1 | Input: [7,8,9,11,12] |
Note:
Your algorithm should run in O(n) time and uses constant extra space.
Putting every number into the right place recuritivly
4, 3, 1, 2, 5
-> 2, 3, 1, 4, 5 ( swap 4, 2 )
-> 3, 2, 1, 4, 5 ( swap 2, 3 )
-> 1, 2, 3, 4, 5 ( swap 1, 3 )
Scan the array, find the first place that not correspond to it’s value
1, 2, 3, 6, 7 ( return 4 )
4, 5, 6, 7, 8 ( return 1 )
1 | public static void swap(int[] list, int a, int b){ |