Java O(n) solution using three pointers


#1
public void sortColors(ArrayList<Integer> a) {
        int left = 0;
        int right = a.size() - 1;
        int itr = left;
        
        while(itr <= right) {
            if(a.get(itr) == 0) {
                Collections.swap(a, left, itr);
                left++;
                itr++;
            } else if(a.get(itr) == 2) {
                Collections.swap(a, itr, right);
                right--;
            } else {
                itr++;
            }
        }
        
    }