题解 | #牛的品种排序III#
牛的品种排序III
https://www.nowcoder.com/practice/f6ab3d7e20f54860886848f0a6374987
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param cows int整型vector
* @param k int整型
* @return int整型vector
*/
vector<int> sortCowsIII(vector<int>& cows, int k) {
// write code here
vector<int>nums(k,0);
for(auto x: cows)
{
nums[x]++;
}
int b = 0;
for(int i=0; i<k; i++)
{
int t = 0;
while(t!=nums[i])
{
cows[b+t] = i;
t++;
}
b = b+t;
}
return cows;
}
};

