一、题目描述
二、算法原理
三、代码实现
class Solution {
public:vector<vector<int>> ret;vector<int> path;vector<bool> check;vector<vector<int>> permuteUnique(vector<int>& nums) {sort(nums.begin(),nums.end());int n=nums.size();check.resize(n,0);dfs(nums);return ret;}void dfs(vector<int>& nums){if(path.size()==nums.size()){ret.push_back(path);return;}int n=nums.size();for(int i=0;i<n;i++){if(check[i]==false&&(i==0||nums[i]!=nums[i-1]||check[i-1]==true)){path.push_back(nums[i]);check[i]=true;dfs(nums);path.pop_back();check[i]=false;}}}