```
public class Solution {
public void sortColors(int[] nums) {
// treat start as stack for 0s and end as stack for 2s
int start = 0;
int end = nums.length-1;
for (int i=0; i<=end;) {
while (nums[i] == 2 && i < end) {
int temp = nums[i];
nums[i] = nums[end];
nums[end] = temp;
end--;
continue;
}
while (nums[i] == 0 && i > start) {
int temp = nums[i];
nums[i] = nums[start];
nums[start] = temp;
start++;
continue;
}
i++;
}
}
}
```