public void sortColors(int[] A) {
        if(A == null || A.length == 0) return;
        int first = 0;
        int end = A.length -1;
        while (first <= end &&A[first] == 0) first++;
        first--;
        while (end >= 0 && A[end] == 2) end--;
        end++;

        int i = first+1;
        while (i < end){
            if(A[i] == 2){
                swap(A,i,--end);
            }
            else if(A[i] == 0){
                swap(A, i++, ++first);
            }
            else {
                i++;
            }
        }
    }