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 ...
随机推荐
- Spring课程 Spring入门篇 1-3Spring框架
课程链接: 1 框架与类库的区别: 框架封装了逻辑,高内聚,类库是松散的工具组合 框架专注于某一个领域,类库通用性较强 2 为什么使用框架: a 业务系统日趋复杂 b 重用度高,开发效率和质量提高 c ...
- Thinkphp 出现 “_CACHE_WRITE_ERROR” 错误的可能解决办法
有可能是老毛病: Cache文件夹和里面的文件,php没有权限 解决办法: chmod -R 777 /.............../www/Cache
- Azure 进阶攻略 | 文件完整性,你打算如何证明?
假设你是一位独立软件开发者,通过自己的网站提供软件下载.网站完全托管在 Azure 中,并且软件下载也是通过 Azure Blob 存储和 Azure CDN 服务提供的. 这做法真不错,不需要自己管 ...
- PyYAML使用
install yum -y install PyYAML document http://www.showyounger.com/show/101586.html http://pyyaml.org ...
- python-gearman使用
yum -y install gearmand chkconfig gearmand on && /etc/init.d/gearmand start # /etc/sysconfig ...
- 笨办法学Python(七)
习题 7: 更多打印 现在我们将做一批练习,在练习的过程中你需要键入代码,并且让它们运行起来.我不会解释太多,因为这节的内容都是以前熟悉过的.这节练习的目的是巩固你学到的东西.我们几个练习后再见.不要 ...
- 安装国际版firefox(火狐浏览器)并设置语言为中文
访问https://www.mozilla.org/zh-CN/firefox/new/?scene=2下载.安装: 访问https://addons.mozilla.org/zh-CN/firefo ...
- 如何用代码的方式取出SAP C4C销售订单创建后所有业务伙伴的数据
比如我创建了一个Sales Order(销售订单)后,如何用代码的方式取出这些通过SAP Partner determination自动填充的Involved Parties信息呢? 一种方法可以使用 ...
- 类型构造器--高阶类型(构造器):Kind (type theory)--类型的元
元类型(0阶类型):nullary type, data types 一元类型(一阶类型):unary adj. [数] 一元的 二元类型: is the kind of a binary ty ...
- react里面Fragments的使用
关于react Fragments,React 中一个常见模式是为一个组件返回多个元素.Fragments 可以让你聚合一个子元素列表,并且不在DOM中增加额外节点. render() { retur ...