Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.

We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.

You must solve this problem without using the library's sort function.

&nbsp;
Example 1:

Input: nums = [2,0,2,1,1,0]
Output: [0,0,1,1,2,2]


Example 2:

Input: nums = [2,0,1]
Output: [0,1,2]


&nbsp;
Constraints:


	n == nums.length
	1 &lt;= n &lt;= 300
	nums[i] is either 0, 1, or 2.


&nbsp;
Follow up:&nbsp;Could you come up with a one-pass algorithm using only&nbsp;constant extra space?

class Solution:
    def sortColors(self, nums: List[int]) -> None:

        red, white, blue = 0, 0, len(nums) - 1

        while white <= blue:
            if nums[white] == 0:
                nums[white], nums[red] = nums[red], nums[white]
                red += 1
                white += 1
            elif nums[white] == 1:
                white += 1
            else:
                nums[white], nums[blue] = nums[blue], nums[white]
                blue -= 1
class Solution {

  public void sortColors(int[] nums) {

    int zeroIndex = 0, twoIndex = nums.length - 1, i = 0;
    while (i <= twoIndex) {
      if (nums[i] == 0)
        swap(nums, zeroIndex++, i++);
      else if (nums[i] == 2)
        swap(nums, twoIndex--, i);
      else
        i++;
    }
  }

  public void swap(int[] nums, int i, int j) {
    int temp = nums[i];
    nums[i] = nums[j];
    nums[j] = temp;
  }
}
class Solution {
public:
    void sortColors(vector<int>& nums) {
        int a =0; int b=0,c=0;int i;
        for(i=0;i<nums.size();i++){
            if(nums[i]==0){
                a++;
            }
            if(nums[i]==1){
                b++;
            }
            else c++;
            
        }
        for(i=0;i<nums.size();i++){
            if(i<a){
                nums[i]=0;
            }
            else if(i<a+b){
                nums[i]=1;
            }
            else nums[i]=2;
        }
      
    }
};
var sortColors = function(nums) {
    let map = {
        '0': 0,
        '1': 0,
        '2': 0
    };
    for(let char of nums) {
        map[char] = map[char] + 1;
    }
    let values = Object.values(map);
    let curr = 0;
    for(let k=0; k<values.length; k++) {
        for(let i=curr; i<curr+values[k]; i++) {
            nums[i] = k;
        }
        curr = curr + values[k];
    }
};
Sort Colors