Straight forward, Brute Force?


  • 0
    T
    class Solution:
    # @param an integer
    # @return a list of string
    def generateParenthesis(self, n):
        res = {'()'}
        for i in range(n-1):
            res = {r[:m+1]+'()'+r[m+1:] for r in res for m in range(i, 2*i+2)}
        return list(res)
    

    It seems set is enough


Log in to reply
 

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