class Solution {
public:
vector<vector<int>> ans;
void dfs(vector<int>& nums, vector<bool>& visited, vector<int>& V) {
bool flag = true;
for(int ii = 0; ii < visited.size(); ii++) {
if(!visited[ii]) {
V.push_back(nums[ii]);
visited[ii] = true;
dfs(nums, visited, V);
V.pop_back();
visited[ii] = false;
flag = false;
}
}
if(flag) ans.push_back(V);
}
vector<vector<int>> permute(vector<int>& nums) {
vector<bool> visited(nums.size(), false);
vector<int> V;
dfs(nums, visited, V);
return ans;
}
};
相关文章
- 10-1546. Permutations 回溯算法
- 10-15【一天一道LeetCode】#46. Permutations
- 10-15[leetcode]46. Permutations全排列(给定序列无重复元素)
- 10-15[LeetCode] 46. Permutations
- 10-15[LeetCode] 46. Permutations(全排列)
- 10-15LeetCode-Day86(C++) 46. 全排列
- 10-15【LeetCode】47. Permutations II 解题报告(Python & C++)
- 10-15leetcode 79. Word Search | 79. 单词搜索(回溯+DFS)
- 10-15LeetCode 1219 黄金矿工[dfs 回溯] HERODING的LeetCode之路
- 10-15Leetcode.面试题 08.12. 八皇后__DFS+回溯