Created
January 23, 2015 08:55
-
-
Save sarchertech/5472c2e6c182f232cf12 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 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