Sort by Color Time : Space : 12345678910111213141516171819202122void dnc(vector<int>& A, int l, int r) { if(l == r) return; int m = l + (r - l) / 2; dnc(A,l,m); dnc(A,m+1,r); vector<int> now; int i = l, j = m + 1; while(i <= m and j <= r) { if(A[i] < A[j]) now.push_back(A[i++]); else now.push_back(A[j++]); } while(i <= m) now.push_back(A[i++]); while(j <= r) now.push_back(A[j++]); for(int i = l, j = 0; i <= r; i++,j++) { A[i] = now[j]; }}void Solution::sortColors(vector<int> &A) { dnc(A,0,A.size() - 1);}