-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22.generate-parentheses.cpp
More file actions
56 lines (52 loc) · 979 Bytes
/
22.generate-parentheses.cpp
File metadata and controls
56 lines (52 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* @lc app=leetcode id=22 lang=cpp
*
* [22] Generate Parentheses
*
* https://leetcode.com/problems/generate-parentheses/description/
*
* algorithms
* Medium (70.53%)
* Likes: 14511
* Dislikes: 547
* Total Accepted: 1.2M
* Total Submissions: 1.6M
* Testcase Example: '3'
*
* Given n pairs of parentheses, write a function to generate all combinations
* of well-formed parentheses.
*
*
* Example 1:
* Input: n = 3
* Output: ["((()))","(()())","(())()","()(())","()()()"]
* Example 2:
* Input: n = 1
* Output: ["()"]
*
*
* Constraints:
*
*
* 1 <= n <= 8
*
*
* n == 1: ["()"]
* n == 2: ["()()","(())"]
* n == 3: ["()()()","((()))","(())()","()(())","(()())"]
*
*/
// @lc code=start
class Solution {
public:
vector<string> myans = {"()"};
void parenthesis(int n){
if
return;
}
vector<string> generateParenthesis(int n) {
parenthesis(n);
return myans;
}
};
// @lc code=end