Skip to content

Instantly share code, notes, and snippets.

@karno
Created April 11, 2010 15:39
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 karno/362818 to your computer and use it in GitHub Desktop.
Save karno/362818 to your computer and use it in GitHub Desktop.
# 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