From c77a85fa7bdfe730931f1f19f53cc714f13d8994 Mon Sep 17 00:00:00 2001 From: Rashid <34310411+frankenstein32@users.noreply.github.com> Date: Sun, 7 Oct 2018 09:30:24 +0530 Subject: [PATCH] Add files via upload --- GenerateParenthesis.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 GenerateParenthesis.py diff --git a/GenerateParenthesis.py b/GenerateParenthesis.py new file mode 100644 index 0000000..e561885 --- /dev/null +++ b/GenerateParenthesis.py @@ -0,0 +1,13 @@ +def bracket(n, asf, open, close): + if n == 0: + if open == close: + print(asf) + return + if open > close: + bracket(n - 1, asf + ")", open, close + 1) + # if close + bracket(n - 1, asf + "(", open + 1, close) + + +n = int(input()) +bracket(2 * n, "", 0, 0)