题解 | #牛的品种排序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 map<int,int> mp; for (auto it : cows) { mp[it]++; } vector<pair<int,int>> data(mp.begin(),mp.end()); vector<int> result; for (auto it : data) { for (int i = 0;i < it.second;++i) { result.push_back(it.first); } } return result; } };