LeetCode算法入门- Generate Parentheses -day16
生活随笔
收集整理的這篇文章主要介紹了
LeetCode算法入门- Generate Parentheses -day16
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
LeetCode算法入門- Generate Parentheses -day16
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:
[
“((()))”,
“(()())”,
“(())()”,
“()(())”,
“()()()”
]
題目分析:給定一個(gè)數(shù)字n,列出所有合法的序列,條件是左括號(hào)個(gè)數(shù)要大于或等于右括號(hào)個(gè)數(shù):使用遞歸來(lái)實(shí)現(xiàn)
Java實(shí)現(xiàn):
總結(jié)
以上是生活随笔為你收集整理的LeetCode算法入门- Generate Parentheses -day16的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 为什么要坚持写博客
- 下一篇: 制图折断线_CAD制图初学入门之CAD标