mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-09 01:11:42 +08:00
移除零宽空格
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
"boundTopicId": 694935,
|
||||
"title": "Truncate Sentence",
|
||||
"titleSlug": "truncate-sentence",
|
||||
"content": "<p>A <strong>sentence</strong> is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of <strong>only</strong> uppercase and lowercase English letters (no punctuation).</p>\n\n<ul>\n\t<li>For example, <code>"Hello World"</code>, <code>"HELLO"</code>, and <code>"hello world hello world"</code> are all sentences.</li>\n</ul>\n\n<p>You are given a sentence <code>s</code> and an integer <code>k</code>. You want to <strong>truncate</strong> <code>s</code> such that it contains only the <strong>first</strong> <code>k</code> words. Return <code>s</code><em> after <strong>truncating</strong> it.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "Hello how are you Contestant", k = 4\n<strong>Output:</strong> "Hello how are you"\n<strong>Explanation:</strong>\nThe words in s are ["Hello", "how" "are", "you", "Contestant"].\nThe first 4 words are ["Hello", "how", "are", "you"].\nHence, you should return "Hello how are you".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "What is the solution to this problem", k = 4\n<strong>Output:</strong> "What is the solution"\n<strong>Explanation:</strong>\nThe words in s are ["What", "is" "the", "solution", "to", "this", "problem"].\nThe first 4 words are ["What", "is", "the", "solution"].\nHence, you should return "What is the solution".</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "chopper is not a tanuki", k = 5\n<strong>Output:</strong> "chopper is not a tanuki"\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 500</code></li>\n\t<li><code>k</code> is in the range <code>[1, the number of words in s]</code>.</li>\n\t<li><code>s</code> consist of only lowercase and uppercase English letters and spaces.</li>\n\t<li>The words in <code>s</code> are separated by a single space.</li>\n\t<li>There are no leading or trailing spaces.</li>\n</ul>\n",
|
||||
"content": "<p>A <strong>sentence</strong> is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of <strong>only</strong> uppercase and lowercase English letters (no punctuation).</p>\n\n<ul>\n\t<li>For example, <code>"Hello World"</code>, <code>"HELLO"</code>, and <code>"hello world hello world"</code> are all sentences.</li>\n</ul>\n\n<p>You are given a sentence <code>s</code> and an integer <code>k</code>. You want to <strong>truncate</strong> <code>s</code> such that it contains only the <strong>first</strong> <code>k</code> words. Return <code>s</code><em> after <strong>truncating</strong> it.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "Hello how are you Contestant", k = 4\n<strong>Output:</strong> "Hello how are you"\n<strong>Explanation:</strong>\nThe words in s are ["Hello", "how" "are", "you", "Contestant"].\nThe first 4 words are ["Hello", "how", "are", "you"].\nHence, you should return "Hello how are you".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "What is the solution to this problem", k = 4\n<strong>Output:</strong> "What is the solution"\n<strong>Explanation:</strong>\nThe words in s are ["What", "is" "the", "solution", "to", "this", "problem"].\nThe first 4 words are ["What", "is", "the", "solution"].\nHence, you should return "What is the solution".</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "chopper is not a tanuki", k = 5\n<strong>Output:</strong> "chopper is not a tanuki"\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 500</code></li>\n\t<li><code>k</code> is in the range <code>[1, the number of words in s]</code>.</li>\n\t<li><code>s</code> consist of only lowercase and uppercase English letters and spaces.</li>\n\t<li>The words in <code>s</code> are separated by a single space.</li>\n\t<li>There are no leading or trailing spaces.</li>\n</ul>\n",
|
||||
"translatedTitle": "截断句子",
|
||||
"translatedContent": "<p><strong>句子</strong> 是一个单词列表,列表中的单词之间用单个空格隔开,且不存在前导或尾随空格。每个单词仅由大小写英文字母组成(不含标点符号)。</p>\n\n<ul>\n\t<li>例如,<code>\"Hello World\"</code>、<code>\"HELLO\"</code> 和 <code>\"hello world hello world\"</code> 都是句子。</li>\n</ul>\n\n<p>给你一个句子 <code>s</code> 和一个整数 <code>k</code> ,请你将 <code>s</code> <strong>截断</strong> ,使截断后的句子仅含 <strong>前</strong> <code>k</code> 个单词。返回 <strong>截断</strong> <code>s</code><em> </em>后得到的句子<em>。</em></p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>s = \"Hello how are you Contestant\", k = 4\n<strong>输出:</strong>\"Hello how are you\"\n<strong>解释:</strong>\ns 中的单词为 [\"Hello\", \"how\" \"are\", \"you\", \"Contestant\"]\n前 4 个单词为 [\"Hello\", \"how\", \"are\", \"you\"]\n因此,应当返回 \"Hello how are you\"\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><strong>输入:</strong>s = \"What is the solution to this problem\", k = 4\n<strong>输出:</strong>\"What is the solution\"\n<strong>解释:</strong>\ns 中的单词为 [\"What\", \"is\" \"the\", \"solution\", \"to\", \"this\", \"problem\"]\n前 4 个单词为 [\"What\", \"is\", \"the\", \"solution\"]\n因此,应当返回 \"What is the solution\"</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre><strong>输入:</strong>s = \"chopper is not a tanuki\", k = 5\n<strong>输出:</strong>\"chopper is not a tanuki\"\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 500</code></li>\n\t<li><code>k</code> 的取值范围是 <code>[1, s 中单词的数目]</code></li>\n\t<li><code>s</code> 仅由大小写英文字母和空格组成</li>\n\t<li><code>s</code> 中的单词之间由单个空格隔开</li>\n\t<li>不存在前导或尾随空格</li>\n</ul>\n",
|
||||
"translatedContent": "<p><strong>句子</strong> 是一个单词列表,列表中的单词之间用单个空格隔开,且不存在前导或尾随空格。每个单词仅由大小写英文字母组成(不含标点符号)。</p>\n\n<ul>\n\t<li>例如,<code>\"Hello World\"</code>、<code>\"HELLO\"</code> 和 <code>\"hello world hello world\"</code> 都是句子。</li>\n</ul>\n\n<p>给你一个句子 <code>s</code> 和一个整数 <code>k</code> ,请你将 <code>s</code> <strong>截断</strong> ,使截断后的句子仅含 <strong>前</strong> <code>k</code> 个单词。返回 <strong>截断</strong> <code>s</code><em> </em>后得到的句子<em>。</em></p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre><strong>输入:</strong>s = \"Hello how are you Contestant\", k = 4\n<strong>输出:</strong>\"Hello how are you\"\n<strong>解释:</strong>\ns 中的单词为 [\"Hello\", \"how\" \"are\", \"you\", \"Contestant\"]\n前 4 个单词为 [\"Hello\", \"how\", \"are\", \"you\"]\n因此,应当返回 \"Hello how are you\"\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre><strong>输入:</strong>s = \"What is the solution to this problem\", k = 4\n<strong>输出:</strong>\"What is the solution\"\n<strong>解释:</strong>\ns 中的单词为 [\"What\", \"is\" \"the\", \"solution\", \"to\", \"this\", \"problem\"]\n前 4 个单词为 [\"What\", \"is\", \"the\", \"solution\"]\n因此,应当返回 \"What is the solution\"</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre><strong>输入:</strong>s = \"chopper is not a tanuki\", k = 5\n<strong>输出:</strong>\"chopper is not a tanuki\"\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 500</code></li>\n\t<li><code>k</code> 的取值范围是 <code>[1, s 中单词的数目]</code></li>\n\t<li><code>s</code> 仅由大小写英文字母和空格组成</li>\n\t<li><code>s</code> 中的单词之间由单个空格隔开</li>\n\t<li>不存在前导或尾随空格</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Easy",
|
||||
"likes": 70,
|
||||
|
Reference in New Issue
Block a user