[Leet Code] Goal Parser Interpreter

Input: command = "G()(al)"
Output: "Goal"
Explanation: The Goal Parser interprets the command as follows:
G -> G
() -> o
(al) -> al
The final concatenated result is "Goal".
Input: command = "G()()()()(al)"
Output: "Gooooal"
Input: command = "(al)G(al)()()G"
Output: "alGalooG"
  • 1 <= command.length <= 100
  • command consists of "G", "()", and/or "(al)" in some order.
class Solution(object):
def interpret(self, command):
"""
:type command: str
:rtype: str
"""
return command.replace("(al)", "al").replace("()", "o")

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store