https://leetcode.com/problems/sort-colors/
计数排序问题
1 class Solution { 2 public: 3 void sortColors(vector<int>& nums) { 4 int rates[3]={0}; 5 int size=nums.size(); 6 for(int i=0;i<size;i++) 7 rates[nums[i]]++; 8 for(int i=0;i<size;i++) 9 { 10 if(rates[0]!=0) 11 { 12 nums[i]=0; 13 rates[0]--; 14 } 15 else if(rates[1]!=0) 16 { 17 nums[i]=1; 18 rates[1]--; 19 } 20 else 21 { 22 nums[i]=2; 23 rates[2]--; 24 } 25 } 26 } 27 };