47. 全排列 II

重复数字去重:

  1. i > 0 && nums[i] == nums[i - 1] && used[i - 1] == false
class Solution {
public:
    void backtraacking(vector<int>& nums,vector<bool>& used)
    {
        if(path.size()==nums.size())
        {
            result.push_back(path);
            return;
        }
        for(int i =0;i<nums.size();i++)
        {
            if(used[i]|| i>0&&nums[i]==nums[i-1]&&used[i-1]==false)continue;
            path.push_back(nums[i]);
            used[i]=true;
            backtraacking(nums,used);
            path.pop_back();
            used[i]=false;
        }
    }
    vector<vector<int>> permuteUnique(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        vector<bool> used(nums.size(),false);
        backtraacking(nums,used);
        return result;
    }
    vector<int> path;
    vector<vector<int>> result;
};