苹果首次开卖翻新iphone, 6s $449# PDA - 掌中宝
b*5
1 楼
first available server == first missing positive
public int firstMissingPositive(int[] A) {
if (A.length == 0) return 1;
int i = 0;
while (i < A.length) {
if (A[i] > A.length || A[i] <= 0)
i++;
else if (A[i] != i+1 && A[A[i]-1] != A[i]) {
int tmp = A[A[i]-1];
A[A[i]-1] = A[i];
A[i] = tmp;
}
else
i++;
}
for (int j = 0; j < A.length; j++) {
if (A[j] != j+1) {
return j+1;
}
}
return A.length+1;
}
public int firstMissingPositive(int[] A) {
if (A.length == 0) return 1;
int i = 0;
while (i < A.length) {
if (A[i] > A.length || A[i] <= 0)
i++;
else if (A[i] != i+1 && A[A[i]-1] != A[i]) {
int tmp = A[A[i]-1];
A[A[i]-1] = A[i];
A[i] = tmp;
}
else
i++;
}
for (int j = 0; j < A.length; j++) {
if (A[j] != j+1) {
return j+1;
}
}
return A.length+1;
}