看不懂1
var firstMissingPositive = function(nums) {
var N = nums.length;
var A = new Uint16Array(N)
for(var i = 0; i < N; i++)
if(nums[i]>0 && nums[i]<=N)
A[nums[i]-1] = nums[i];
for(var i = 0; i < N; i++)
if(A[i] != i+1)
return i+1;
return N+1;
};
看不懂2
var firstMissingPositive = function(nums) {
var start = 0;
var end = nums.length - 1;
while (start <= end) {
var index = nums[start] - 1;
if (index == start)
start++;
else if (index < 0 || index > end || nums[start] == nums[index])
nums[start] = nums[end--];
else {
nums[start] = nums[index];
nums[index] = index + 1;
}
}
return start + 1;
};