**Difficulty: Medium**

**Frequency: N/A**

Given a collection of numbers that might contain duplicates, return all possible unique permutations.

For example,

`[1,1,2]`

have the following unique permutations:

`[1,1,2]`

, `[1,2,1]`

, and `[2,1,1]`

.

**My solution:**

**Data structure:**

**Steps:**

**Complexity:**

**Test cases:**

**Corner cases:**

**Code:**

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

**Another solution:**

**Data structure:**

**steps:**

**Complexity**:

**Code**:

**Things to learn:**