1. class Solution {
  2. public:
  3. vector<string> removeComments(vector<string>& source) {
  4. vector<string> res;
  5. string ln;
  6. int state = ;
  7. for (const auto & line : source) {
  8. for (int i = , ll = line.length(); i < ll; i++) {
  9. if (state == ) {
  10. if (i < ll-) {
  11. if (line[i] == '/' && line[i+] == '/')
  12. break; // // comment, skip line
  13. else if (line[i] == '/' && line[i+] == '*') {
  14. state = ;
  15. i += ;
  16. continue;
  17. }
  18. }
  19. ln.push_back(line[i]);
  20. }
  21. else if (state == ) { // inside /*
  22. if (i < ll- && line[i] == '*' && line[i+] == '/') {
  23. state = ;
  24. i += ;
  25. continue;
  26. }
  27. }
  28. }
  29. if (state == && ln.length() > ) {
  30. res.push_back(ln);
  31. ln = "";
  32. }
  33. }
  34. if (ln.length() > )
  35. res.push_back(ln);
  36. return res;
  37. }
  38. };

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. intellijidea课程 intellijidea神器使用技巧 4-1 重构

    1 重构变量 shift + F6 将选中的变量以及用到该变量的部分全部修改 2 重构方法 Ctrl  + F6 重构变量

  2. Python常用模块(四)

    一.re模块 正则表达式时计算机科学的一个概念,正则表达式通常被用来检索,替换那些符合某个模式的文本,大多数程序设计语言都支持利用正则表达式进行字符串操作. 正则就是用一些具有特殊含义的符号组合到一起 ...

  3. mac笔记本上的工具

    svn可是换工具:cornerstone host修改工具:switchHosts!

  4. 让你的sharepoint2013具有EMS快递查询的功能

    <iframe name="kuaidi100" src="http://www.kuaidi100.com/frame/app/index2.html" ...

  5. Struts2_带参数的结果集

    页面请求: <a href="user/user?type=1">传参数</a> action: public Integer type; public S ...

  6. django orm 时间字段讲解

    创建django的model时,有DateTimeField.DateField和TimeField三种类型可以用来创建日期字段,其值分别对应着datetime().date().time()三中对象 ...

  7. Windows下hosts文件的作用

    原文地址:https://my.oschina.net/u/874225/blog/194348 在操作系统中的路径:Win7在C:\Windows\System32\drivers\etc目录下 内 ...

  8. php:定义时间跳转到指定页面

    我们想要定义延迟时间,再跳转到指定页面,只要用header()即可,语法: header("Refresh:延迟时间;url=要跳转的页面"); 例子: 注意注意:我们在heade ...

  9. 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 ...

  10. css3弹性盒子

    CSS3 弹性盒子(Flex Box) 弹性盒子是 CSS3 的一种新的布局模式. CSS3 弹性盒( Flexible Box 或 flexbox),是一种当页面需要适应不同的屏幕大小以及设备类型时 ...