We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6c1df07 commit ff3e57eCopy full SHA for ff3e57e
1 file changed
허현빈/10주차/Generate Parentheses.js
@@ -0,0 +1,25 @@
1
+/**
2
+ * @param {number} n
3
+ * @return {string[]}
4
+ */
5
+var generateParenthesis = function(n) {
6
+ const ans = [];
7
+
8
+ const bk = (str, open, close) => {
9
+ if (str.length === 2 * n) {
10
+ ans.push(str);
11
+ return;
12
+ }
13
14
+ if (open < n) {
15
+ dfs(str + "(", open + 1, close);
16
17
18
+ if (close < open) {
19
+ dfs(str + ")", open, close + 1);
20
21
+ };
22
23
+ bk("", 0, 0);
24
+ return ans;
25
+};
0 commit comments