Easy to understand c++ code


  • -1
    M

    class Solution {
    private:
    vector<vector<int>> res;
    public:
    vector<vector<int>> permute(vector<int>& nums) {
    subpermute(0,nums);
    return res;
    }
    void subpermute(int first, vector<int>& nums){
    if(first == nums.size()){
    res.push_back(nums);
    return;
    }
    for(int i=first;i<nums.size();++i){
    swap(nums[first],nums[i]);
    subpermute(first+1,nums);
    swap(nums[first],nums[i]);
    }
    }
    };


Log in to reply
 

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