Open Ni-Guvara opened 1 year ago
class Solution { public: vector<vector<int>> ans; vector<int> path; int rec[21] = {0}; vector<vector<int>> permute(vector<int>& nums) { int len = nums.size(); backtracing(nums , len); return ans; } void backtracing(vector<int> & nums , int len) { if(path.size() >= len) { ans.push_back(path); return; } for(int i = 0 ; i < len ; i++) { if(rec[nums[i]+10]) continue; path.push_back(nums[i]); rec[nums[i] + 10] = 1; backtracing(nums , len); path.pop_back(); rec[nums[i] + 10] = 0; } } };