LeeCode - brackets generation

给出 n 代表生成括号的对数,请你写出一个函数,使其能够生成所有可能的并且有效的括号组合。

例如,给出 n = 3,生成结果为:

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

  • Solution a:
    mathematical induction from n = 1 -> n = 2 -> n = x, from small to large, we found rule.

  • Solution two:

    DFS + recursive word symbol length 2 * n
    violent solution, binding the stack

    O (2 ** 2n)

  • Solution three:
    improvement Solution two pruning +
    O (2 ** n)

Guess you like

Origin www.cnblogs.com/yeni/p/11611881.html