My AC code in c++


  • 0
    1
    class Solution {
    public:
        vector<vector<int>> res;
        vector<int> ans;
        vector<vector<int>> permute(vector<int>& nums) {
            fun(nums,0,ans);
            return res;
        }
        void fun(vector<int> &nums,int n,vector<int> ans){
            if(n==nums.size()){
                res.push_back(ans);
                return;
            }
            for(int i=0;i<nums.size();i++){
                if(find(ans.begin(),ans.end(),nums[i]) != ans.end()) continue;
                ans.push_back(nums[i]);
                fun(nums,n+1,ans);
                ans.pop_back();
            }
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.