题解 | #牛群排列组合#
牛群排列组合
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 int n = nums.size(); set<vector<int>> res; recurse(nums,0,res); vector<vector<int>> ret(res.rbegin(),res.rend()); return ret; } void recurse(vector<int> & nums, int start, set<vector<int>> &res){ if(start == nums.size()-1){ res.insert(nums); return; } for(int i = start;i<nums.size();i++){ swap(nums[start],nums[i]); recurse(nums, start + 1,res); swap(nums[start],nums[i]); } } };