Ruby Prefix Solution


  • 0
    R
    def subsets(nums)
        if nums.empty?
            return [[]]
        end
        
        result = [[]]
        nums.each_with_index do |num, index|
            subsets(nums[index + 1...nums.length]).each do |subset|
                result << [num] + subset
            end
        end
        result
    end
    

Log in to reply
 

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