c++ recursive solution


  • 0
    B
    class Solution {
    public:
        vector<vector<int>> result;
        
        void helper(vector<int> &nums, int start, vector<int> cur){
            result.push_back(cur);
            
            for(int i=start;i<nums.size();i++){
                cur.push_back(nums[i]);
                helper(nums, i+1, cur);
                cur.pop_back();
            }
            return ;
        }
        
        vector<vector<int>> subsets(vector<int>& nums) {
            vector<int> cur;
            helper(nums, 0, cur);
            return result;
        }
    };
    

Log in to reply
 

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