Created
August 8, 2011 12:39
-
-
Save taicki/1131681 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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