class Solution {
public:
vector<vector<int>> permute(vector<int>& nums) {
vector<vector<int>> res;
vector<int> record;
vector<bool> used(nums.size(), false);
helper(res, nums, record, used);
return res;
}
private:
void helper(vector<vector<int>>& res, vector<int>& nums, vector<int>& record, vector<bool>& used) {
if (record.size() == nums.size()) {
res.push_back(record);
return;
}
for (int i = 0 ; i < nums.size(); i++) {
if (!used[i]) {
used[i] = true;
record.push_back(nums[i]);
helper(res, nums, record, used);
record.pop_back();
used[i] = false;
}
}
}
};