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 ...
随机推荐
- intellijidea课程 intellijidea神器使用技巧 4-1 重构
1 重构变量 shift + F6 将选中的变量以及用到该变量的部分全部修改 2 重构方法 Ctrl + F6 重构变量
- Python常用模块(四)
一.re模块 正则表达式时计算机科学的一个概念,正则表达式通常被用来检索,替换那些符合某个模式的文本,大多数程序设计语言都支持利用正则表达式进行字符串操作. 正则就是用一些具有特殊含义的符号组合到一起 ...
- mac笔记本上的工具
svn可是换工具:cornerstone host修改工具:switchHosts!
- 让你的sharepoint2013具有EMS快递查询的功能
<iframe name="kuaidi100" src="http://www.kuaidi100.com/frame/app/index2.html" ...
- Struts2_带参数的结果集
页面请求: <a href="user/user?type=1">传参数</a> action: public Integer type; public S ...
- django orm 时间字段讲解
创建django的model时,有DateTimeField.DateField和TimeField三种类型可以用来创建日期字段,其值分别对应着datetime().date().time()三中对象 ...
- Windows下hosts文件的作用
原文地址:https://my.oschina.net/u/874225/blog/194348 在操作系统中的路径:Win7在C:\Windows\System32\drivers\etc目录下 内 ...
- php:定义时间跳转到指定页面
我们想要定义延迟时间,再跳转到指定页面,只要用header()即可,语法: header("Refresh:延迟时间;url=要跳转的页面"); 例子: 注意注意:我们在heade ...
- 859. Buddy Strings (wrong 4 times so many cases to test and consider) if else**
Given two strings A and B of lowercase letters, return true if and only if we can swap two letters i ...
- css3弹性盒子
CSS3 弹性盒子(Flex Box) 弹性盒子是 CSS3 的一种新的布局模式. CSS3 弹性盒( Flexible Box 或 flexbox),是一种当页面需要适应不同的屏幕大小以及设备类型时 ...