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 ...
随机推荐
- Hibernate课程 初探一对多映射4-1 inverse属性
1 <Set>节点的inverse属性默认由one方来维护(默认值为false).将inverse属性修改为true则由多方来维护.
- css 引入方式以及css的选择器
一.css的引入方式: 1.行内样式 <div> <p style="color: red">我是一个段落</p> </div> 2 ...
- 关于基于Linphone的视频通话Android端开发过程中遇到的问题
关于基于Linphone的视频通话Android端开发过程中遇到的问题 运用开源项目Linphone的SDK进行开发,由于是小组进行开发,我主要负责的是界面部分. 由于当时是初学Android开发,对 ...
- Struts2_HelloWorld_7_2
第一个程序的流程图: Struts2.x 的作用:把请求和展现分开.
- 笨办法学Python(四)
习题 4: 变量(variable)和命名 你已经学会了 print 和算术运算.下一步你要学的是“变量”.在编程中,变量只不过是用来指代某个东西的名字.程序员通过使用变量名可以让他们的程序读起来更像 ...
- MySQL入门很简单: 12 MYSQL 用户管理
1. 权限表 安装MySQL会自动安装一个名为mysql的数据库,存储权限表: user表, db表,host表,table_priv表,columns_priv表,proc_priv表等. 1)us ...
- 微信的 rpx
微信小程序新单位rpx与自适应布局 rpx是微信小程序新推出的一个单位,按官方的定义,rpx可以根据屏幕宽度进行自适应,在rpx出现之前,web页面的自适应布局已经有了多种解决方案,为什么微信还捣 ...
- C# 驱动的mongodb的分页查询简单示例
/// <summary> /// mongodb分页查询 /// </summary> /// <typeparam name="T">< ...
- 前端高质量知识(五)-JS详细图解全方位解读this
在这之前,我们需要来回顾一下执行上下文. 在前面几篇文章中,我有好几个地方都提到执行上下文的生命周期,为了防止大家没有记住,再次来回顾一下,如下图. 执行上下文生命周期 在执行上下文的创建阶段,会分别 ...
- NOIP2018学军中学游记(11.09~11.11)
前言 这篇博客记录的是我在\(NOIP2018\)提高组比赛中的经历. 这一次的\(NOIP\)是在学军中学举办的, 莫名感到一阵慌张. 但愿能有一个好成绩,不然就要\(AFO\)了... ... 说 ...