天天看点

leetcode:第 218 场周赛:设计 Goal 解析器(字符串)

题目:

leetcode:第 218 场周赛:设计 Goal 解析器(字符串)

分析:

一道水题,把最后一个空出来的思路很好。

代码:

class Solution {
public:
    string interpret(string command) {
        string s="";
        for(int i=0;i<command.size()-1;i++)
        {
            if(command[i]=='G') 
            {
                s+=command[i];
                continue;
            }
            if(command[i]=='(' && command[i+1]==')')
            {
                s+='o';
                i++;
                continue;
            }
            i++;
            while(command[i]!=')')
            {
                s+=command[i];
                i++;
            }
        }
        if(command[command.size()-1]=='G') s+=command[command.size()-1];
        return s;
    }
};