leetcode46. 全排列

class Solution {
public:
    bool flag[10];
    vector<vector<int>> ans;
    vector<int>path;
    void dfs(vector<int>&nums,int u){
        int n=nums.size();
        if(u==n)ans.push_back(path);
        for(int i=0;i<n;i++){
            if(!flag[i]){
                path.push_back(nums[i]);
                flag[i]=true;
                dfs(nums,u+1);
                flag[i]=false;
                path.pop_back();
            }
        }
    }
    vector<vector<int>> permute(vector<int>& nums) {
        dfs(nums,0);
        return ans;
    }
};