题解 | #牛的品种排序II#
牛的品种排序II
https://www.nowcoder.com/practice/43e49fbb98b4497ba46e185918188b1c
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param cows int整型vector
* @return int整型vector
*/
vector<int> sortCows(vector<int>& cows) {
// write code here
vector<int>a(3,0);
for(auto x:cows)
a[x]++;
int j=0;
for(int i=0;i<cows.size();)
{
if(a[j])
{
cows[i]=j;
a[j]--;
i++;
}
else{
j++;
}
}
return cows;
}
};
