Skip to content

Commit 28032b3

Browse files
author
Bhrigu Kansra
authored
Merge pull request #121 from frankenstein32/master
Add files via upload
2 parents 4b5f10c + c77a85f commit 28032b3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

GenerateParenthesis.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def bracket(n, asf, open, close):
2+
if n == 0:
3+
if open == close:
4+
print(asf)
5+
return
6+
if open > close:
7+
bracket(n - 1, asf + ")", open, close + 1)
8+
# if close
9+
bracket(n - 1, asf + "(", open + 1, close)
10+
11+
12+
n = int(input())
13+
bracket(2 * n, "", 0, 0)

0 commit comments

Comments
 (0)