题解 | #牛群排列组合#C++
牛群排列组合
https://www.nowcoder.com/practice/3db87961faf34094b5115775be588126
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @return int整型vector<vector<>> */ vector<vector<int> > cow_permutation(vector<int>& nums) { // write code here //应该还可以优化,自己写next_permutation按照递减返回 sort(nums.begin(), nums.end()); vector<vector<int>> res; res.push_back(nums); while (next_permutation(nums.begin(), nums.end())) { res.push_back(nums); } sort(res.begin(), res.end(), [](vector<int>& a, vector<int>& b) { for (int i = 0; i < a.size(); ++i) { if (a[i] == b[i]) continue; return a[i] > b[i]; } return a[0] > b[0]; }); return res; } };