Solution:
We can use any kind of sort.
I implemented bubble sort for this problem. Obviously this is not the best method.
Code:
class Solution {
public:
void sortColors(vector<int>& nums) {
//bubble sort, one pass
for(int i = 0; i < nums.size(); i++){
int j = i-1;
int temp = nums[i];
if(nums[j] > temp){
while(j>=0 && nums[j] > temp){
nums[j+1] = nums[j];
j--;
}
nums[j+1] = temp;
}
}
}
};