题解 | #牛的品种排序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 // 冒泡排序 int len = cows.size(); for(int i=len-1; i>=0; --i) { for(int j=1; j<=i; ++j) { // 数值大的往后移动; if(cows[j-1]>cows[j]) { int temp = cows[j]; cows[j] = cows[j-1]; cows[j-1] = temp; } } } return cows; } };
虚数五行区解题中心 文章被收录于专栏
非淡泊无以明志,非宁静无以致远