Skip to content

Instantly share code, notes, and snippets.

@austinschwartz
Created January 22, 2018 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save austinschwartz/03fcf1eb682886484a7989a9dbd8d94f to your computer and use it in GitHub Desktop.
Save austinschwartz/03fcf1eb682886484a7989a9dbd8d94f to your computer and use it in GitHub Desktop.
def parens(n, l = 0, r = 0, curr = ""):
if len(curr) == n:
print(curr)
if l < n // 2:
parens(n, l + 1, r, curr + '(')
if r < l:
parens(n, l, r + 1, curr + ')')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment