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