Simple recursive solution, JS


  • 0
    R
    var res; 
    var subsets = function(source) {
        res = [];
        subsetsRec([],source)
        return res;
    };
    
    function subsetsRec(arr,source) {
        res.push(arr.sort(function(a, b) {
            return a - b 
        }));
        if(source.length !== 0) {
            for(var i = 0; i < source.length; i++) 
                subsetsRec(arr.concat(source[i]),source.slice(i+1,source.length));
        }
    }

Log in to reply
 

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