Share my python solution with recursively


  • 0
    class Solution(object):
    def generateParenthesis(self, n):
        """
        :type n: int
        :rtype: List[str]
        """
        if n==0:return []
        if n==1:return ['()']
        res=[]
        for item in self.generateParenthesis(n-1):
            for i in xrange(len(item)-1):
                s=item[0:i+1]+'()'+item[i+1:]
                res.append(s)
            res.append('()'+item)
            res.append(item+'()')
        return list(set(res))
    

    this solution is come from http://blog.csdn.net/feliciafay/article/details/17414981


Log in to reply
 

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