Leetcode 22. Generate Parentheses(python)

笨笨的回溯

感觉自己代码很丑。。

class Solution(object):
    def generateParenthesis(self, n):
        """
        :type n: int
        :rtype: List[str]
        """
        res=""
        solution=[]
        self.backtrack(res,solution,n,0,0)
        return solution
        
    def backtrack(self,res,solution,n,l,r):
        if r>l:
            return 
        if len(res)==2*n:
            solution.append(res)
            return
        candidate=[]
        if l

  

 

转载于:https://www.cnblogs.com/colorss/p/5359983.html

你可能感兴趣的:(Leetcode 22. Generate Parentheses(python))