1678.设计Goal解析器
链接:1678.设计Goal解析器
难度:Easy
标签:字符串
简介:给你字符串 command ,返回 Goal 解析器 对 command 的解释结果。
题解 1 - cpp
- 编辑时间:2022-11-06
- 执行用时:4ms
- 内存消耗:6MB
- 编程语言:cpp
- 解法介绍:遍历。
class Solution {
public:
string interpret(string command) {
int n = command.size();
string ans = "";
for (int i = 0; i < n; i++) {
if (command[i] == 'G') ans += "G";
else if (command[i] == '(' && command[i + 1] == ')') ans += "o", i += 1;
else ans += "al", i += 3;
}
return ans;
}
};