Advertisement
Guest User

my solution

a guest
Oct 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. class Solution {
  2. public:
  3. void fun (vector <int> &nums , int idx, vector < vector <int>> &res, vector <int> path, unordered_map <int, bool> &vis)
  4. {
  5. if (path.size() == nums.size())
  6. {
  7. res.push_back(path);
  8. return ;
  9. }
  10.  
  11. for (int i = 0 ; i < nums.size(); i ++)
  12. {
  13. if (vis[nums[i]]) continue;
  14. path.push_back(nums[i]);
  15. vis[nums[i]] = true;
  16. fun(nums, i, res, path, vis);
  17. path.pop_back();
  18. vis[nums[i]] = false;
  19. }
  20. }
  21. vector<vector<int>> permute(vector<int>& nums) {
  22.  
  23. vector < vector <int>> res;
  24. vector <int> path;
  25. unordered_map <int, bool> vis;
  26. fun (nums, 0, res, path, vis);
  27.  
  28. return res;
  29.  
  30.  
  31. }
  32. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement