class Solution {
public:
vector<vector<int>> result;
vector<int> path;
void backtracking(vector<int>& nums, vector<bool>& visited) {
if(path.size() == nums.size()) {
result.push_back(path);
return;
}
for(int i = 0; i < nums.size(); i++) {
if(visited[i] == false) {
path.push_back(nums[i]);
visited[i] = true;
backtracking(nums, visited);
path.pop_back();
visited[i] = false;
}
}
}
vector<vector<int>> permute(vector<int>& nums) {
vector<bool> visited(nums.size(), false);
backtracking(nums, visited);
return result;
}
};