class Solution {
public:
    vector<vector<int> > permute(vector<int> &num) {
        vector<vector<int>> res;
        vector<int> path;
        vector<bool> used(num.size(), false);
        dfs(num, res, path, used);
        return res;
     }
     void dfs(vector<int>& num, vector<vector<int>>& res, vector<int> path, vector<bool>& used){
         if(path.size() == num.size()){
             res.push_back(path);
             return;
         }
         for(int i=0; i<num.size(); i++){
             if(used[i]==true)
                 continue;
             used[i] = true;
             path.push_back(num[i]);
             dfs(num, res, path, used);
             path.pop_back();
             used[i] = false;
         }
     }
    
};

https://www.programmercarl.com/0046.%E5%85%A8%E6%8E%92%E5%88%97.html#%E5%85%B6%E4%BB%96%E8%AF%AD%E8%A8%80%E7%89%88%E6%9C%AC