###### ＃16 Permutations II

Given a list of numbers with duplicate number in it. Find all uniquepermutations.

Example

For numbers [1,2,2] the unique permutations are:

[
[1,2,2],
[2,1,2],
[2,2,1]
]

Mycode（AC ＝ 290ms）：

class Solution {
public:
/**
* @param nums: A list of integers.
* @return: A list of unique permutations.
*/
vector<vector<int> > permuteUnique(vector<int> &nums) {
vector<vector<int>> ans;
if (nums.size() == 0) return ans;

vector<int> sofar;
unordered_set<int> visited;
return ans;
}

void permute(vector<vector<int>>& ans,
vector<int>& sofar,
vector<int>& nums,
unordered_set<int>& visited,
{
if (sofar.size() == nums.size()) {
ans.push_back(sofar);
}
return;
}

for (int i = 0; i < nums.size(); i++) {
if (visited.find(i) == visited.end()) {
sofar.push_back(nums[i]);
visited.insert(i);

sofar.pop_back();
visited.erase(i);
}
}
}
};

#### [leetcode]47. Permutations II,python实现

2016-06-16 16:24:48

#### 【leetcode】【47】Permutations II

2016-03-01 10:17:28

#### 47. Permutations II | Java最短代码实现

2016-03-20 21:15:43

#### Permutations II -- LeetCode

2014-03-20 01:04:36

#### Leetcode 47. Permutations II

2016-03-28 21:46:07

#### [LeetCode]47.Permutations II

2015-01-19 12:21:00

#### leetcode 47. Permutations II-排列|回溯算法

2016-06-12 15:11:12

#### [LeetCode][Java] Permutations II

2015-07-14 11:56:32

#### leetcode - 47. Permutations II(全排列)

2017-06-29 16:21:55

#### Permutations -- LeetCode

2014-03-20 00:44:12

## 不良信息举报

＃16 Permutations II