题目
代码
执行用时:32 ms, 在所有 Python3 提交中击败了82.54% 的用户
内存消耗:14.9 MB, 在所有 Python3 提交中击败了65.53% 的用户
通过测试用例:105 / 105
class Solution:
def interpret(self, command: str) -> str:
command=command.replace("()","o")
command=command.replace("(al)","al")
return command
【方法2】
执行用时:40 ms, 在所有 Python3 提交中击败了33.56% 的用户
内存消耗:14.9 MB, 在所有 Python3 提交中击败了73.47% 的用户
通过测试用例:105 / 105
class Solution:
def interpret(self, command: str) -> str:
ans=""
length=len(command)
idx=0
while idx<length:
if command[idx]=='G':
ans+="G"
idx+=1
elif command[idx]=="(" and command[idx+1]==')':
idx+=2
ans+="o"
else:
idx+=4
ans+="al"
return ans