2025-08-10 10:08:24 +0000 UTC

Goal Parser Interpretation

Code

class Solution:
    def interpret(self, command: str) -> str:
        stack = []
        res = []
        for char in command:
            if char == ")":
                if stack:
                    res.extend(stack)
                    stack.clear()
                else:
                    res.append("o")
            elif char == "G":
                res.append("G")
            elif char != "(":
                stack.append(char)
        return "".join(res)