class Solution {
public:
vector<vector<int>> result;
vector<int> path;
void backtracing(vector<int>& nums,vector<bool>& used)
{
if(path.size()==nums.size())
{
result.push_back(path);
return;
}
for(int i=0;i<nums.size();i++)
{
if(used[i]==true) continue;
used[i]=true;
path.push_back(nums[i]);
backtracing(nums,used);
path.pop_back();
used[i]=false;
}
}
vector<vector<int>> permute(vector<int>& nums) {
result.clear();
path.clear();
vector<bool> used(nums.size(),false);
backtracing(nums,used);
return result;
}
};
leetcode每日一题第163天
最新推荐文章于 2024-09-07 10:12:58 发布