Goal Parser Interpretation (Leetcode 1678)

Problem Link: https://leetcode.com/problems/goal-parser-interpretation/

class Solution:
    def interpret(self, command: str) -> str:
        
        ans=''
        i=0
        while(i<len(command)):
            if(command[i]=='G'):
                ans=ans+'G'
                i+=1
            elif(command[i]=='(' and command[i+1]==')'):
                ans=ans+'o'
                i+=2
            else:
                ans=ans+'al'
                i+=4
        return ans

Last updated