Easy understandable C++ code.


  • 0
    N
    class Solution {
    public:
        vector<vector<int> >vv;
        int taken[100];
        void per(vector<int>& nums,vector<int>& temp)
        {
            if(temp.size()==nums.size())
            {
                vv.push_back(temp);
                return;
            }
            for(int j=0;j<nums.size();j++)
            {
                if(taken[j]==0)
                {
                    temp.push_back(nums[j]);
                    taken[j]=1;
                    per(nums,temp);
                    taken[j]=0;
                    temp.pop_back();
                }
            }
        }
        vector<vector<int>> permute(vector<int>& nums) {
            memset(taken,0,sizeof(taken));
            vector<int>v;
            per(nums,v);
            return vv;
        }
    };

Log in to reply
 

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