全排列 Permutations

it2022-07-05  168

class Solution { public: vector<vector<int>> permute(vector<int>& nums) { sort(nums.begin(),nums.end()); vector<vector<int>> res; vector<int> path; trackback(res,path,nums); return res; } void trackback(vector<vector<int>> &res,vector<int> &path,vector<int> &nums) { if(path.size() == nums.size()) { res.push_back(path); return ; } for(auto i:nums) { auto pos=find(path.begin(),path.end(),i); if(pos==path.end()) { path.push_back(i); trackback(res,path,nums); path.pop_back(); } } } };

  

转载于:https://www.cnblogs.com/yanqi110/p/4932768.html


最新回复(0)