时间4 ms
击败
19.38%
内存5.9 MB
击败
84.78%
解题思路:遍历字符串以此找到你所需要的解析的字符并赋值给新的字符串
class Solution {
public:
string interpret(string command) {
string res ;
for(int i = 0 ; i < command.size() ; i++){
if(command[i] == 'G'){
res.push_back(command[i]);
}
if(command[i] == '(' && command[i+1] == ')'){
res.push_back('o');
i++;
}
else if(command[i] == '(' && command[i+1] == 'a'){
res.push_back (command[i+1]);
res.push_back (command[i+2]);
i = i+3;
}
}
return res;
}
};