Skip to content

Instantly share code, notes, and snippets.

@taicki
Created August 8, 2011 12:39
Show Gist options
  • Save taicki/1131681 to your computer and use it in GitHub Desktop.
Save taicki/1131681 to your computer and use it in GitHub Desktop.
def paren(n):
if n == 1:
return ['()']
results = paren(n-1)
coms = set()
for i in results:
coms.add('()'+i)
coms.add('('+i+')')
coms.add(i+'()')
return coms
from pprint import pprint
pprint(paren(4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment