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课程 初探一对多映射5-2 Eclipse添加数据库连接
1 Eclipse新建java项目 2 Windows ==> show view == >other ==>Data source Explorer 3 左侧视图 database ...
- MySQL慢查询分析工具pt-query-digest详解
一.简介 pt-query-digest是用于分析mysql慢查询的一个工具,它可以分析binlog.General log.slowlog,也可以通过SHOWPROCESSLIST或者通过tcpdu ...
- ActiveMQ实例2--Spring JMS发送消息
参考文章:http://my.oschina.net/xiaoxishan/blog/381209#OSC_h3_7 一,步骤参照参考文献 二.新建的项目 三.补充 web.xml <?xml ...
- #include stdio.h(4)
#include <stdio.h> int main() { //****************1.数组*************** //什么是数组:专门用来存放数据的 /* 格式 ...
- 跨平台图表控件TeeChart使用教程:导入XML数据
TeeChart的最新版中包含了一个自动加载XML数据的新组件.这个组件的名字叫做TTeeXMLSource,用户可以在TeeXML.pas unit中找到这个组件. 加载XML图表所需的最小属性是& ...
- css3骰子(transform初识)
利用css3制作可旋转的骰子,效果图如下,也可以查看 demo: 首先是骰子的html结构,.page 是骰子的六个页面的 class,#one-#six分别表示六个面,.point 是骰子表面的点数 ...
- Android 仿微信朋友圈拍小视频上传到服务器
这个接上一个写的实现拍小视频和传到服务器的 界面是这个样子滴. 我也知不知道怎么给图片搞小一点o(╯□╰)o 布局文件是这样的[认真脸] <?xml version="1.0&quo ...
- C#变量、常量
变量 一.命名变量:标识符 为变量命名时要遵循C#语言的命名规范: 1.变量名只能由字母.数字和下划线组成,而不能包含空格.标点符号.运算符等其他符号 2.变量名不能与C#中的关键字名称相同 二. ...
- 解决dubbo-admin管控台不能显示服务的问题
1.首先在网上下载了dubbo-admin.war,解压后修改dubbo.properties文件 dubbo.registry.address=zookeeper://127.0.0.1:2181 ...
- MSSQL复制分发对异构数据库之间大容量数据分发造成异常
由于历史遗留的问题,现有的架构中存在采用MSSQL的复制分发功能,从Oracle发布数据到MSSQL. 关于这项发布的实现原理,官方表述如下: Oracle 事务发布是通过使用 SQL Server ...