不好想,用桶排序解决。
int findMissingPostive(int A[], int n)
{
bucket_sort(A, n);
for (int i = ; i < n; i++)
if (A[i] != i + )
return i + ; return n + ; } void bucket_sort(int A[], int n)
{
for (int i = ; i < n; i++)
{
while (A[i] != i + )
{
if (A[i]<= || A[i]>n || A[i] == A[A[i] - ])
break; swap(A[i], A[A[i] - ]);
}
}
}