# 全排列 II

<p>给定一个可包含重复数字的序列 <code>nums</code> ，<strong>按任意顺序</strong> 返回所有不重复的全排列。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>nums = [1,1,2]<strong><br />输出：</strong>[[1,1,2], [1,2,1], [2,1,1]]</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>nums = [1,2,3]<strong><br />输出：</strong>[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]</pre><p> </p><p><strong>提示：</strong></p><ul>	<li><code>1 <= nums.length <= 8</code></li>	<li><code>-10 <= nums[i] <= 10</code></li></ul>

以下程序实现了这一功能，请你填补空白处内容：

```cpp
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
	vector<vector<int>> permuteUnique(vector<int> &nums)
	{
		vector<vector<int>> res;
		vector<bool> used(nums.size());
		sort(nums.begin(), nums.end());
		dfs(nums, used, res);
		return res;
	}
private:
	vector<int> stack;
	void dfs(vector<int> &nums, vector<bool> &used, vector<vector<int>> &res)
	{
		if (stack.size() == nums.size())
		{
			res.push_back(stack);
		}
		else
		{
			for (int i = 0; i < nums.size(); i++)
			{
				if (!used[i])
				{
					_____________________;
					stack.push_back(nums[i]);
					used[i] = true;
					dfs(nums, used, res);
					stack.pop_back();
					used[i] = false;
				}
			}
		}
	}
};
```

## template

```cpp
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
	vector<vector<int>> permuteUnique(vector<int> &nums)
	{
		vector<vector<int>> res;
		vector<bool> used(nums.size());
		sort(nums.begin(), nums.end());
		dfs(nums, used, res);
		return res;
	}
private:
	vector<int> stack;
	void dfs(vector<int> &nums, vector<bool> &used, vector<vector<int>> &res)
	{
		if (stack.size() == nums.size())
		{
			res.push_back(stack);
		}
		else
		{
			for (int i = 0; i < nums.size(); i++)
			{
				if (!used[i])
				{
					if (i > 0 && !used[i - 1] && nums[i - 1] == nums[i])
					{
						continue;
					}
					stack.push_back(nums[i]);
					used[i] = true;
					dfs(nums, used, res);
					stack.pop_back();
					used[i] = false;
				}
			}
		}
	}
};
```

## 答案

```cpp
if (i > 0 && !used[i - 1] && nums[i - 1] == nums[i])
{
	continue;
}
```

## 选项

### A

```cpp
if (i > 0 && !used[i - 1] && nums[i - 1] == nums[i])
{
	break;
}
```

### B

```cpp
if (nums[i - 1] == nums[i])
{
	continue;
}
```

### C

```cpp
if (nums[i - 1] == nums[i])
{
	break;
}
```