leetcode刷题报告 之hrt篇 oa leetcode 722 Remove Comments python

这篇博客主要介绍了如何从C++源代码中移除注释,包括行注释(//)和块注释(/* ... */)。文章详细解释了处理这两种注释的规则,并通过例子说明了特殊情况的处理,如嵌套注释和行尾的注释。博主强调了解题过程中的陷阱,如不能简单地按行处理,以及需要使用标志变量来跟踪是否在块注释中。
摘要由CSDN通过智能技术生成

Given a C++ program, remove comments from it. The program source is an array of strings source where source[i] is the ith line of the source code. This represents the result of splitting the original source code string by the newline character ‘\n’.

In C++, there are two types of comments, line comments, and block comments.

The string “//” denotes a line comment, which represents that it and the rest of the characters to the right of it in the same line should be ignored.
The string “/" denotes a block comment, which represents that all characters until the next (non-overlapping) occurrence of "/” should be ignored. (Here, occurrences happen in reading order: line by line from left to right.) To be clear, the string “/*/” does not yet end the block comment, as the ending would be overlapping the beginning.
The first effective comment takes precedence over others.

For example, if the string “//” occurs in a block comment, it is ignored.
Similarly, if the string “/*” occurs in a line or block comment, it is also ignored.
If a certain line of code is empty after removing comments, you must not output that line: each string in the answer list will be non-empty.

There will be no control characters, single quote, or double quote characters.

For example, source = “string s = “/* Not a comment. */”;” will not be a test case.
Also, nothing else such as defines or macros will interfere with the comments

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值