【发布时间】:2019-06-06 10:12:16
【问题描述】:
Leetcode 上的标准 Generate Parenthesis 题如下
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
[
"((()))",
"(()())",
"(())()",
"()(())",
"()()()"
]
在解决方案选项卡中,他们解释了Closure Number Method,我觉得很难理解。
我对代码进行了试运行,甚至得到了正确答案,但似乎无法理解它为什么起作用?这种方法背后的直觉是什么?
任何帮助将不胜感激!
【问题讨论】:
-
如果我有时间我会回答这个问题,但是如果你用谷歌搜索Catalan Number 并开始阅读你可能会找到一些帮助。加泰罗尼亚数字也与Motzkin Numbers 有关。
-
Code Golf 这些概念很有趣。这是我创建的与 Motzkin 数字相关的一个 - Enumerate binary trees
-
感兴趣的:Catalan Numbers Tom Davis
-
我添加了加泰罗尼亚语tag。标签中有很多不错的链接。
-
@Guy Coder 非常感谢!我会看看这些概念。