当前位置:网站首页>LeetCode 1678、设计 Goal 解析器
LeetCode 1678、设计 Goal 解析器
2022-04-22 12:17:00 【亡于灬】
1678、设计 Goal 解析器
1)题目描述
请你设计一个可以解释字符串 command 的 Goal 解析器 。command 由 "G"、"()" 和/或 "(al)" 按某种顺序组成。Goal 解析器会将 "G" 解释为字符串 "G"、"()" 解释为字符串 "o" ,"(al)" 解释为字符串 "al" 。然后,按原顺序将经解释得到的字符串连接成一个字符串。
给你字符串 command ,返回 Goal 解析器 对 command 的解释结果。
示例 1:
输入:command = "G()(al)"
输出:"Goal"
解释:Goal 解析器解释命令的步骤如下所示:
G -> G
() -> o
(al) -> al
最后连接得到的结果是 "Goal"
示例 2:
输入:command = "G()()()()(al)"
输出:"Gooooal"
示例 3:
输入:command = "(al)G(al)()()G"
输出:"alGalooG"
提示:
1 <= command.length <= 100command由"G"、"()"和/或"(al)"按某种顺序组成
2)分析
一次遍历。直接遍历模拟即可。
3)C++代码
class Solution {
public:
string interpret(string command) {
string res;
for(int i=0;i<command.length();i++){
if(command[i]=='G')
res+='G';
else if(command[i]=='('){
if(command[++i]==')')
res+='o';
else{
res+="al";
i+=2;
}
}
}
return res;
}
};
版权声明
本文为[亡于灬]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_38342510/article/details/124337797
边栏推荐
- What does 0ul or 1ul in STM32 mean?
- 在VSCode中设置滑动滚轮改变字体大小
- 带你详细入门华为云会议【玩转华为云】
- UML summary
- Difference between redis setex and set
- zuul使用中的一些问题
- 4.21 learning record DP record path (LCS) knapsack on tree (course selection) general tree DP (dance without boss)
- 【并发编程055】如下守护线程是否会执行finally模块中的代码?
- 基于J2EE的房屋租赁系统的设计与实现.rar(论文+项目源码+数据库文件)
- Oracle Data Guard和金仓KingbaseES集群的数据保护模式对比
猜你喜欢

MySQL之父:代码应该一次写成,而不是后面再改

Efr32 crystal calibration guide

【并发编程054】多线程的状态及转换过程?

Interpretation of tamigou project | 49.5% equity transfer of Beijing Hualong pawn Co., Ltd

腾讯云域名绑定

【生活中的逻辑谬误】以暴制暴和压制理性
![【深入理解TcaplusDB技术】更替列表指定位置数据接口说明——[List表]](/img/ed/cccd5dee09d2f0a3e6c788bd265b36.png)
【深入理解TcaplusDB技术】更替列表指定位置数据接口说明——[List表]

MySQL 5.0 installation tutorial illustration detailed tutorial

congratulations! You have been concerned about the official account for 1 years, and invite you to join NetEase data analysis training.

In depth analysis of the drawing source code process of view
随机推荐
电工第二讲
LeetCode 389、找不同
Case 4-1.7: file transfer (concurrent search)
电路实验——实验四 戴维南定理与诺顿定理
congratulations! You have been concerned about the official account for 1 years, and invite you to join NetEase data analysis training.
"Open source summer" activity is hot. In the registration, rich bonuses are waiting for you to get!
[in depth understanding of tcallusdb technology] data interface description for reading the specified location in the list - [list table]
Base64 encryption, decryption and JSON processing
前三个月免费试用!博睿数据告警平台OneAlert火热大促进行中
UML总结
JS 【详解】作用域
zuul使用中的一些问题
ESP32-CAM使用历
通俗易懂地给女朋友讲:线程池的内部原理
The higher the refresh rate, the better?
Comparison of data protection modes between Oracle data guard and Jincang kingbasees cluster
论文阅读《Attention Concatenation Volume for Accurate and Efficient Stereo Matching》
Canvas series tutorial 01 - line, triangle, polygon, rectangle, palette
日撸代码300行学习笔记 Day 47
分布式监控CAT服务端的本地部署