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的更多相关文章

  1. 【LeetCode】722. Remove Comments 解题报告(Python)

    [LeetCode]722. Remove Comments 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/remove-c ...

  2. LeetCode 722. Remove Comments

    原题链接在这里:https://leetcode.com/problems/remove-comments/ 题目: Given a C++ program, remove comments from ...

  3. LC 722. Remove Comments

    Given a C++ program, remove comments from it. The program source is an array where source[i] is the  ...

  4. 【leetcode】722. Remove Comments

    题目如下: Given a C++ program, remove comments from it. The program source is an array where source[i] i ...

  5. [LeetCode] Remove Comments 移除注释

    Given a C++ program, remove comments from it. The program source is an array where source[i] is the ...

  6. [Swift]LeetCode722. 删除注释 | Remove Comments

    Given a C++ program, remove comments from it. The program source is an array where source[i] is the  ...

  7. LeetCode All in One题解汇总(持续更新中...)

    突然很想刷刷题,LeetCode是一个不错的选择,忽略了输入输出,更好的突出了算法,省去了不少时间. dalao们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对 ...

  8. leetcode 学习心得 (4)

    645. Set Mismatch The set S originally contains numbers from 1 to n. But unfortunately, due to the d ...

  9. All LeetCode Questions List 题目汇总

    All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...

随机推荐

  1. hystrix应用介绍(一)

    声明:本文仅做个人的一次接口重构过程记录,期间参考了一些写的不错的博客,如果存在抄袭,请留言. hystrix基本介绍 hystrix 是一个开源的容灾框架,目的是为了解决当依赖服务出现故障或者接口响 ...

  2. 1064. 计算斐波那契第n项 通项公式

    题目描述 输入n,编写程序输出斐波那契数列的第n项.其中斐波那契数列f(n)的定义如下: f(1)=0,f(2)=1         f(n)=f(n-1)+f(n-2)(n>=2) 输入 一行 ...

  3. aliyun maven repository

    <mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> & ...

  4. 缩小javascript文件大小之缩编、混淆

    写前端的相信都遇到过要提高网页的性能,其中javascript文件越小,浏览器的下载速度面对文件的读取和解析就更快.而一般我们在开发又需要一定的代码规范来使我们的代码更加的容易维护和读懂,但是大量空格 ...

  5. 栅格那点儿事(四D)

    统计值与空值 在上一篇的内容里反复提到了一个统计值.那这个统计值是怎么来的,具体是干嘛用的呢? 统计值主要就是用于栅格数据的显示和重分类,顾名思义就是一个波段中所有像元值的一个统计信息,最大值,最小值 ...

  6. Android 编码风格规范,很赞哦

    1. 前言 这份文档参考了 Google Java 编程风格规范和 Google 官方 Android 编码风格规范.该文档仅供参考,只要形成一个统一的风格,见量知其意就可. 1.1 术语说明 在本文 ...

  7. 使用Excel调用ABAP系统的函数

    效果:在excel里创建一个按钮,开发一些VB script,可以连接指定的ABAP系统并执行系统里的ABAP function module. 在这里例子里执行ABAP系统的函数TH_USER_LI ...

  8. Xcode SDK模拟器安装及安装路径

    将SDK想要装的版本,将SDK包放入‘mac中的SDK安装路径’.再将Xcode模拟器重启. 再打开Xcode模拟器,就可以在菜单栏的 ‘硬件’->’设备‘->’iPhone Retina ...

  9. 位图算法-hash算法的后继应用

    判断集合中存在重复是常见编程任务之一,当集合中数据量比较大时我们通常希望少进行几次扫描,这时双重循环法就不可取了.位图法比较适合于这种情况,它的做法是按照集合中最大元素max创建一个长度为max+1的 ...

  10. ios 逆向工程文档汇总

    iOS逆向工程工具集 http://www.jianshu.com/p/7f9511d48e05 移动App入侵与逆向破解技术-iOS篇 http://blog.csdn.net/heiby/arti ...