class Solution {
public:
vector<vector<int>> res;
vector<int> path;
bool st[10];
void dfs(vector<int> nums,int u)
{
if(u==nums.size())
{
res.push_back(path);
return;
}
for(int i=0;i<nums.size();i++)
{
if(i&&nums[i]==nums[i-1]&&!st[i-1]) continue;
if(!st[i])
{
st[i]=true;
path.push_back(nums[i]);
dfs(nums,u+1);
path.pop_back();
st[i]=false;
}
}
}
vector<vector<int>> permuteUnique(vector<int>& nums) {
sort(nums.begin(),nums.end());
dfs(nums,0);
return res;
}
};
标签:nums,int,47,dfs,II,vector,res,LeetCode
From: https://www.cnblogs.com/tangxibomb/p/17471853.html