美文网首页
22. Generate Parentheses

22. Generate Parentheses

作者: 我是你的果果呀 | 来源:发表于2016-12-14 06:23 被阅读0次

Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.

For example, givenn= 3, a solution set is:

["((()))", "(()())", "(())()", "()(())", "()()()" ]

有效组合的基本条件是有多少个左括号,就得有相应的右括号与之对应上。 所以第二个判断条件是 right < left. 如果将right < max, 得到的结果是左右括号相等的组合数, 不考虑是否有效。

you

相关文章

网友评论

      本文标题:22. Generate Parentheses

      本文链接:https://www.haomeiwen.com/subject/nvfimttx.html