3 line DP Solution


  • -3
    A
    def generate_parenthesis(n)
        (1..n).inject([[""]]) { |acc, i|
            acc << (0...i).map { |x| acc[x].product(acc[i - x - 1]).map { |a, b| "(#{a})#{b}"} }.flatten
        }.last
    end

Log in to reply
 

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