题目链接: https://leetcode.com/problems/permutations/description/
//与subset差不多
//1. 返回数组长度要一致
//2. 重复的数字要剔除掉
class Solution {
public:
vector<vector<int>> permute(vector<int>& nums) {
vector<vector<int>> subs;
vector<int> sub;
if(nums.empty())
return subs;
helper(subs,sub,nums);
return subs;
}
void helper(vector<vector<int>>& subs ,vector<int> sub , vector<int>& nums){
if(sub.size() == nums.size()) {
subs.push_back(sub);
return;
}
for(int i = 0 ; i< nums.size(); i++){
if(count(sub.begin(),sub.end(),nums[i]) == count(nums.begin(),nums.end(),nums[i]) ) {
continue;
}
sub.push_back(nums[i]);
helper(subs,sub,nums);
sub.pop_back();
}
}
};