题解 | #没有重复项数字的全排列#
没有重复项数字的全排列
https://www.nowcoder.com/practice/4bcf3081067a4d028f95acee3ddcd2b1
#include <vector> class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param num int整型vector * @return int整型vector<vector<>> */ vector<vector<int>> ans; void dfs(vector<int> tmp,vector<bool> used,vector<int>& num){ if(tmp.size() == num.size()){ ans.push_back(tmp); return; } for(int i = 0;i<num.size();i++){ if(used[i] == false){ tmp.push_back(num[i]); used[i] = true; dfs(tmp, used, num); used[i] = false; tmp.pop_back(); } } } vector<vector<int>> permute(vector<int>& num) { int size = num.size(); vector<bool> used(size,false); vector<int> tmp; dfs(tmp,used,num); return ans; } };