class Solution {
/**
* @param nums: A list of integer which is 0, 1 or 2
* @return: nothing
*/
public void sortColors(int[] nums) {
// write your code here
HashMap<Integer,Integer> map=new HashMap<Integer, Integer>();
for(int i=0;i<nums.length;i++){
if(!map.containsKey(nums[i])){
map.put(nums[i], 1);
}else{
map.put(nums[i], map.get(nums[i])+1);
}
}
int zeroCount=map.get(0);
int oneCount=map.get(1);
int twoCount=map.get(2);
for(int i=0;i<zeroCount;i++){
nums[i]=0;
}
for(int i=zeroCount;i<zeroCount+oneCount;i++){
nums[i]=1;
}
for(int i=zeroCount+oneCount;i<nums.length;i++){
nums[i]=2;
}
}
}