Created
April 11, 2010 15:39
-
-
Save karno/362818 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# http://vipprog.tumblr.com/post/48288901/quiz-add-parenthese | |
def CompleteBracket(arg): | |
lt = 0 | |
gt = 0 | |
i = 0 | |
for c in arg : | |
if c == "(" : | |
gt += 1 #閉じ待ち追加 | |
elif c == ")" : | |
if gt == 0 : | |
lt += 1 #開き待ち追加 | |
else : | |
gt -= 1 | |
return "(" * lt + arg + ")" * gt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment