首页 > 其他 > 详细

leetcode-mid-backtracking -22. Generate Parentheses

时间:2019-06-04 10:06:46      阅读:127      评论:0      收藏:0      [点我收藏+]

mycode    没有思路,大早上就有些萎靡,其实和上一个电话号码的题如出一辙啦

参考:

class Solution(object):
    def generateParenthesis(self, n):
        """
        :type n: int
        :rtype: List[str]
        """
        def dfs(temp,l,r):
            if l == 0 and r == 0:
                res.append(temp)
                #return 
            if l>0:
                dfs(temp+(,l-1,r)
            if r>l and r>0:
                dfs(temp+),l,r-1)                   
        res = []
        dfs(‘‘,n,n)
        return res

 

leetcode-mid-backtracking -22. Generate Parentheses

原文:https://www.cnblogs.com/rosyYY/p/10971768.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!