SHARE
TWEET

my solution

a guest Oct 21st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top