class Solution {
public:
vector<vector<int>> res;
vector<int> path;
bool used[10];
void dfs(vector<int>& nums) {
if (path.size() == nums.size()) {
res.push_back(path);
return;
}
for (int i = 0; i < nums.size(); i ++) {
if (!used[i]) {
used[i] = true;
path.push_back(nums[i]);
dfs(nums);
path.pop_back();
used[i] = false;
}
}
}
vector<vector<int>> permute(vector<int>& nums) {
dfs(nums);
return res;
}
};
标签:排列,nums,46,back,used,vector,path,LeetCode,size
From: https://www.cnblogs.com/hjy94wo/p/16658110.html