public void sortColors(int[] nums) {
        int zero = 0, two = nums.length - 1;
        // one-pass solution
        for (int i = 0; i <= two; ++i) {
            while (nums[i] == 2 && i < two) {
                swap(nums, i, two);
                --two;
            }
            while (nums[i] == 0 && i > zero) {
                swap(nums, i, zero);
                ++zero;
            }
        }
    }