We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f29f437 commit 8423603Copy full SHA for 8423603
22.括号生成.js
@@ -0,0 +1,25 @@
1
+/**
2
+ * @param {number} n
3
+ * @return {string[]}
4
+ */
5
+var generateParenthesis = function(n) {
6
+ const ans = [];
7
+ function walk(str, l, r) {
8
+ if (l >= n && r >= n) {
9
+ ans.push(str);
10
+ return;
11
+ }
12
+ if (l <= r) {
13
+ walk(str + '(', l + 1, r);
14
+ } else {
15
+ if (l < n) {
16
17
18
+ if (r < n) {
19
+ walk(str + ')', l, r + 1);
20
21
22
23
+ walk('', 0, 0);
24
+ return ans;
25
+};
0 commit comments