
class Solution {
public:
string interpret(string command) {
string res;
for (int i = 0; i < command.size(); i++) {
if (command[i] == 'G') {
res += "G";
} else if (command[i] == '(') {
if (command[i + 1] == ')') {
res += "o";
} else {
res += "al";
}
}
}
return res;
}
};
本文介绍了一个C++类,该类包含一个名为interpret的方法,用于解析特定格式的命令字符串。当遇到'G'时,直接将其添加到结果字符串中;当遇到'('后跟')'时,将'o'添加到结果字符串;当遇到'(al)'时,则将'al'添加到结果字符串。通过此方法可以将输入的命令字符串转换为另一种形式。
169万+

被折叠的 条评论
为什么被折叠?



