题解 | #排列颜色#
排列颜色
http://www.nowcoder.com/practice/4345e55fdb03498a89a97ec18e62b3ab
class Solution { public: void sortColors(int A[], int n) { int zeroPos = -1, twoPos = n, idx = 0; while (idx < twoPos) { if (A[idx] == 1) ++idx; else if (A[idx] == 0) swap(A[idx++], A[++zeroPos]); else swap(A[idx], A[--twoPos]); } } };