722. Remove Comments
class Solution {
public:
vector<string> removeComments(vector<string>& source) {
vector<string> res;
string ln;
int state = ;
for (const auto & line : source) {
for (int i = , ll = line.length(); i < ll; i++) {
if (state == ) {
if (i < ll-) {
if (line[i] == '/' && line[i+] == '/')
break; // // comment, skip line
else if (line[i] == '/' && line[i+] == '*') {
state = ;
i += ;
continue;
}
}
ln.push_back(line[i]);
}
else if (state == ) { // inside /*
if (i < ll- && line[i] == '*' && line[i+] == '/') {
state = ;
i += ;
continue;
}
}
}
if (state == && ln.length() > ) {
res.push_back(ln);
ln = "";
}
}
if (ln.length() > )
res.push_back(ln);
return res;
}
};
722. Remove Comments的更多相关文章
- 【LeetCode】722. Remove Comments 解题报告(Python)
[LeetCode]722. Remove Comments 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/remove-c ...
- LeetCode 722. Remove Comments
原题链接在这里:https://leetcode.com/problems/remove-comments/ 题目: Given a C++ program, remove comments from ...
- LC 722. Remove Comments
Given a C++ program, remove comments from it. The program source is an array where source[i] is the ...
- 【leetcode】722. Remove Comments
题目如下: Given a C++ program, remove comments from it. The program source is an array where source[i] i ...
- [LeetCode] Remove Comments 移除注释
Given a C++ program, remove comments from it. The program source is an array where source[i] is the ...
- [Swift]LeetCode722. 删除注释 | Remove Comments
Given a C++ program, remove comments from it. The program source is an array where source[i] is the ...
- LeetCode All in One题解汇总(持续更新中...)
突然很想刷刷题,LeetCode是一个不错的选择,忽略了输入输出,更好的突出了算法,省去了不少时间. dalao们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对 ...
- leetcode 学习心得 (4)
645. Set Mismatch The set S originally contains numbers from 1 to n. But unfortunately, due to the d ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
随机推荐
- jQuery遍历节点
html代码 <div> <p>武汉长乐教育</p> <span>在哪才能真正学习会PHP技术?</span> <a href=&qu ...
- python面试题——基础篇(80题)
1.为什么学习Python? Python是一门优秀的综合语言, Python的宗旨是简明.优雅.强大,在人工智能.云计算.金融分析.大数据开发.WEB开发.自动化运维.测试等方向应用广泛 2.通过什 ...
- u-boot分析(二)----工作流程分析
u-boot分析(二) 由于这两天家里有点事,所以耽误了点时间,没有按时更新,今天我首先要跟大家说说我对于u-boot分析的整体的思路,然后呢我以后的博客会按照这个内容更新,希望大家关注. 言归正传, ...
- 【Troubleshooting 】Outlook 客户端无法显示电子邮件图像
出于安全原因,Outlook 2013/2016不会在电子邮件中显示图像,但您可以右键单击图像并选择" 下载图片 "选项.我最近注意Outlook停止显示图像,并且没有下载图像的选 ...
- easyUI 节点树选择
定义: <input id="treeFFatherId" name="treeFFatherId" value="" style=& ...
- HCNA配置telnet远程管理
1.拓扑图 说明:通过配置最终能通过R5 用telnet协议登陆到R4上并将R4改名为R44 2.R4配置 <Huawei>sys Enter system view, return us ...
- C++学习之虚析构函数
什么样的情况下才需要虚析构函数? 类需要控制自己的对象执行一系列操作时发生什么样的行为,这些操作包括:创建(对象).拷贝.移动.赋值和销毁.在继承体系中,如果一个类(基类或其派生的类)没有定义拷贝控制 ...
- APP专项测试使用到的工具
最近在读<大话APP测试>,我也就是把需要使用的测试点做一个总结,目前是使用的工具进行的整理,后期慢慢把工具使用案例贴出来
- POJ-2151 Check the difficulty of problems---概率DP好题
题目链接: https://vjudge.net/problem/POJ-2151 题目大意: ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 问 每队至少解出一题且冠军队至少解出N ...
- 2018.7.26 进程和线程的区别 &&你对 Java平台的理解
进程和线程的区别 1.定义 进程:具有一定独立功能的程序关于某个数据集合上的一次运行活动,进程是系统进行资源分配和调度的一个独立单位. 线程:进程的一个实体,是CPU调度和分派的基本单位,它是比进程更 ...