mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-22 21:46:46 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>给一个 C++ 程序,删除程序中的注释。这个程序<code>source</code>是一个数组,其中<code>source[i]</code>表示第 <code>i</code> 行源码。 这表示每行源码由<font color=\"#c7254e\"><font face=\"Menlo, Monaco, Consolas, Courier New, monospace\"><span style=\"font-size:12.6px\"><span style=\"background-color:#f9f2f4\"> <code>'\\n' </code></span></span></font></font>分隔。</p>\n\n<p>在 C++ 中有两种注释风格,行内注释和块注释。</p>\n\n<ul>\n\t<li>字符串<code>//</code> 表示行注释,表示<code>//</code>和其右侧的其余字符应该被忽略。</li>\n\t<li>字符串<code>/*</code> 表示一个块注释,它表示直到下一个(非重叠)出现的<code>*/</code>之间的所有字符都应该被忽略。(阅读顺序为从左到右)非重叠是指,字符串<code>/*/</code>并没有结束块注释,因为注释的结尾与开头相重叠。</li>\n</ul>\n\n<p>第一个有效注释优先于其他注释。</p>\n\n<ul>\n\t<li>如果字符串<code>//</code>出现在块注释中会被忽略。</li>\n\t<li>同样,如果字符串<code>/*</code>出现在行或块注释中也会被忽略。</li>\n</ul>\n\n<p>如果一行在删除注释之后变为空字符串,那么<strong>不要</strong>输出该行。即,答案列表中的每个字符串都是非空的。</p>\n\n<p>样例中<strong>没有</strong>控制字符,单引号或双引号字符。</p>\n\n<ul>\n\t<li>比如,<code>source = \"string s = \"/* Not a comment. */\";\"</code> 不会出现在测试样例里。</li>\n</ul>\n\n<p>此外,没有其他内容(如定义或宏)会干扰注释。</p>\n\n<p>我们保证每一个块注释最终都会被闭合, 所以在行或块注释之外的<code>/*</code>总是开始新的注释。</p>\n\n<p>最后,隐式换行符<strong>可以</strong>通过块注释删除。 有关详细信息,请参阅下面的示例。</p>\n\n<p>从源代码中删除注释后,需要以相同的格式返回源代码。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong> source = [\"/*Test program */\", \"int main()\", \"{ \", \" // variable declaration \", \"int a, b, c;\", \"/* This is a test\", \" multiline \", \" comment for \", \" testing */\", \"a = b + c;\", \"}\"]\n<strong>输出:</strong> [\"int main()\",\"{ \",\" \",\"int a, b, c;\",\"a = b + c;\",\"}\"]\n<strong>解释:</strong> 示例代码可以编排成这样:\n/*Test program */\nint main()\n{ \n // variable declaration \nint a, b, c;\n/* This is a test\n multiline \n comment for \n testing */\na = b + c;\n}\n第 1 行和第 6-9 行的字符串 /* 表示块注释。第 4 行的字符串 // 表示行注释。\n编排后: \nint main()\n{ \n \nint a, b, c;\na = b + c;\n}</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong> source = [\"a/*comment\", \"line\", \"more_comment*/b\"]\n<strong>输出:</strong> [\"ab\"]\n<strong>解释:</strong> 原始的 source 字符串是 \"a/*comment<strong>\\n</strong>line<strong>\\n</strong>more_comment*/b\", 其中我们用粗体显示了换行符。删除注释后,隐含的换行符被删除,留下字符串 \"ab\" 用换行符分隔成数组时就是 [\"ab\"].\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= source.length <= 100</code></li>\n\t<li><code>0 <= source[i].length <= 80</code></li>\n\t<li><code>source[i]</code> 由可打印的 <strong>ASCII</strong> 字符组成。</li>\n\t<li>每个块注释都会被闭合。</li>\n\t<li>给定的源码中不会有单引号、双引号或其他控制字符。</li>\n</ul>\n<span style=\"display:block\"><span style=\"height:0px\"><span style=\"position:absolute\"><span style=\"top:0px\"><span style=\"left:-9999px\"><span style=\"opacity:0\"><span style=\"overflow:hidden\"> </span></span></span></span></span></span></span>",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 70,
|
||||
"likes": 71,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Mini Parser\", \"titleSlug\": \"mini-parser\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u8ff7\\u4f60\\u8bed\\u6cd5\\u5206\\u6790\\u5668\"}, {\"title\": \"Ternary Expression Parser\", \"titleSlug\": \"ternary-expression-parser\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u4e09\\u5143\\u8868\\u8fbe\\u5f0f\\u89e3\\u6790\\u5668\"}]",
|
||||
@@ -143,7 +143,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"5.9K\", \"totalSubmission\": \"18.1K\", \"totalAcceptedRaw\": 5873, \"totalSubmissionRaw\": 18105, \"acRate\": \"32.4%\"}",
|
||||
"stats": "{\"totalAccepted\": \"6.1K\", \"totalSubmission\": \"18.6K\", \"totalAcceptedRaw\": 6072, \"totalSubmissionRaw\": 18566, \"acRate\": \"32.7%\"}",
|
||||
"hints": [
|
||||
"Carefully parse each line according to the following rules:\r\n\r\n* If we start a block comment and we aren't in a block, then we will skip over the next two characters and change our state to be in a block.\r\n\r\n* If we end a block comment and we are in a block, then we will skip over the next two characters and change our state to be *not* in a block.\r\n\r\n* If we start a line comment and we aren't in a block, then we will ignore the rest of the line.\r\n\r\n* If we aren't in a block comment (and it wasn't the start of a comment), we will record the character we are at.\r\n\r\n* At the end of each line, if we aren't in a block, we will record the line."
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user