void sortColors(int A[], int n) {
int r=0,w=0,b=n-1;
for(w=0;w<=b;) {
if(A[w]==0)
swap(A[r++],A[w++]); // why also w++? because r's next position can only be white
else if(A[w]==2)
swap(A[b--],A[w]);
else
w++;
}
}
leetcode:Sort Colors
最新推荐文章于 2024-07-14 14:55:48 发布