Prefix to Postfix Conversion
Given an expression in prefix notation, convert it to postfix notation. In prefix notation, an operator is placed before its operands, while in postfix notation, the operator is placed after its operands.
[ "*+AB-CD" ]
Explanation. The prefix expression '* + A B - C D' converts to the postfix expression 'A B + C D - *'.
[ "+A*BC" ]
Explanation. The prefix expression '+ A * B C' converts to the postfix expression 'A B C * +'.
[ "-+7*45+20" ]
Explanation. The prefix expression '- + 7 * 4 5 + 2 0' converts to the postfix expression '7 4 5 * + 2 0 + -'.
Follow-up: Can you optimize your solution to run in linear time complexity?
The input string will only contain single-digit integers and operators `+`, `-`, `*`, and `/`. The string will be a valid prefix expression.
- Views
- 2