1class Solution {23public void sortColors(int[] nums) {45int zeroIndex = 0, twoIndex = nums.length - 1, i = 0;6while (i <= twoIndex) {7if (nums[i] == 0) swap(nums, zeroIndex++, i++);8else if (nums[i] == 2) swap(nums, twoIndex--, i);9else i++;10}11}1213public void swap(int[] nums, int i, int j) {14int temp = nums[i];15nums[i] = nums[j];16nums[j] = temp;17}18}