Skip to content

Instantly share code, notes, and snippets.

@sarchertech
Created January 23, 2015 08:55
Show Gist options
  • Save sarchertech/5472c2e6c182f232cf12 to your computer and use it in GitHub Desktop.
Save sarchertech/5472c2e6c182f232cf12 to your computer and use it in GitHub Desktop.
def answer(str):
stack = []
out = ""
for c in str:
if c == "*":
stack.append(c)
elif c == "+":
while (peek(stack) == "*"):
out = out + stack.pop()
out = out + c
else:
out = out + c
while stack:
out = out + stack.pop()
return out
def peek(stack):
if stack:
return stack[-1]
else:
return ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment