Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- void fun (vector <int> &nums , int idx, vector < vector <int>> &res, vector <int> path, unordered_map <int, bool> &vis)
- {
- if (path.size() == nums.size())
- {
- res.push_back(path);
- return ;
- }
- for (int i = 0 ; i < nums.size(); i ++)
- {
- if (vis[nums[i]]) continue;
- path.push_back(nums[i]);
- vis[nums[i]] = true;
- fun(nums, i, res, path, vis);
- path.pop_back();
- vis[nums[i]] = false;
- }
- }
- vector<vector<int>> permute(vector<int>& nums) {
- vector < vector <int>> res;
- vector <int> path;
- unordered_map <int, bool> vis;
- fun (nums, 0, res, path, vis);
- return res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement