GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing leetcode.cn — 722. 删除注释 - 力扣(LeetCode) 题目描述 题目描述 题解 题解 提交记录 提交记录 中等 给一个 C++ 程序,删除程序中的注释。这个程序 在 C++ 中有两种注释风格,行内注释和块注释。
第一个有效注释优先于其他注释。
如果一行在删除注释之后变为空字符串,那么不要输出该行。即,答案列表中的每个字符串都是非空的。 样例中没有控制字符,单引号或双引号字符。
此外,没有其他内容(如定义或宏)会干扰注释。 我们保证每一个块注释最终都会被闭合, 所以在行或块注释之外的 最后,隐式换行符可以通过块注释删除。 有关详细信息,请参阅下面的示例。 从源代码中删除注释后,需要以相同的格式返回源代码。
示例 1: 输入: source = ["/*Test program */", "int main()", "{ ", " // variable declaration ", "int a, b, c;", "/* This is a test", " multiline ", " comment for ", " testing */", "a = b + c;", "}"]
输出: ["int main()","{ "," ","int a, b, c;","a = b + c;","}"]
解释: 示例代码可以编排成这样:
/*Test program */
int main()
{
// variable declaration
int a, b, c;
/* This is a test
multiline
comment for
testing */
a = b + c;
}
第 1 行和第 6-9 行的字符串 /* 表示块注释。第 4 行的字符串 // 表示行注释。
编排后:
int main()
{
int a, b, c;
a = b + c;
}
示例 2: 输入: source = ["a/*comment", "line", "more_comment*/b"] 输出: ["ab"] 解释: 原始的 source 字符串是 "a/*comment\nline\nmore_comment*/b", 其中我们用粗体显示了换行符。删除注释后,隐含的换行符被删除,留下字符串 "ab" 用换行符分隔成数组时就是 ["ab"].
提示:
代码 代码 测试用例 测试用例 测试结果 测试结果 |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |