P19947 [GeeksforGeeks] Generate all possible parentheses
普及
题目描述

Given an integer N representing the number of pairs of parentheses, the task is to generate all combinations of well-formed(balanced) parentheses.
Example 1:
Input:
N = 3
Output:
((()))
(()())
(())()
()(())
()()()
Example 2:
Input:
N = 1
Output:
()
Your Task:
You don't need to read input or print anything. Complete the function AllParenthesis() which takes N as input parameter and returns the list of balanced parenthesis.
Expected Time Complexity: O(2^{N} * N).
Expected Auxiliary Space: O(2NX), X = Number of valid Parenthesis.
Constraints:
1 ≤ N ≤ 12

输入格式

见题面

输出格式

见题面

样例输入
N = 3
样例输出
((())) (()()) (())() ()(()) ()()()