Skip to content

Commit ff3e57e

Browse files
committed
[leet] bk
1 parent 6c1df07 commit ff3e57e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)