1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-08 17:01:42 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

移除零宽空格

This commit is contained in:
2025-05-25 15:06:02 +08:00
parent 59597532bc
commit 3070bed723
272 changed files with 1031 additions and 749 deletions

View File

@@ -6,7 +6,7 @@
"boundTopicId": null,
"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>&quot;Hello World&quot;</code>, <code>&quot;HELLO&quot;</code>, and <code>&quot;hello world hello world&quot;</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>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = &quot;Hello how are you Contestant&quot;, k = 4\n<strong>Output:</strong> &quot;Hello how are you&quot;\n<strong>Explanation:</strong>\nThe words in s are [&quot;Hello&quot;, &quot;how&quot; &quot;are&quot;, &quot;you&quot;, &quot;Contestant&quot;].\nThe first 4 words are [&quot;Hello&quot;, &quot;how&quot;, &quot;are&quot;, &quot;you&quot;].\nHence, you should return &quot;Hello how are you&quot;.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = &quot;What is the solution to this problem&quot;, k = 4\n<strong>Output:</strong> &quot;What is the solution&quot;\n<strong>Explanation:</strong>\nThe words in s are [&quot;What&quot;, &quot;is&quot; &quot;the&quot;, &quot;solution&quot;, &quot;to&quot;, &quot;this&quot;, &quot;problem&quot;].\nThe first 4 words are [&quot;What&quot;, &quot;is&quot;, &quot;the&quot;, &quot;solution&quot;].\nHence, you should return &quot;What is the solution&quot;.</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = &quot;chopper is not a tanuki&quot;, k = 5\n<strong>Output:</strong> &quot;chopper is not a tanuki&quot;\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= s.length &lt;= 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>&quot;Hello World&quot;</code>, <code>&quot;HELLO&quot;</code>, and <code>&quot;hello world hello world&quot;</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>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = &quot;Hello how are you Contestant&quot;, k = 4\n<strong>Output:</strong> &quot;Hello how are you&quot;\n<strong>Explanation:</strong>\nThe words in s are [&quot;Hello&quot;, &quot;how&quot; &quot;are&quot;, &quot;you&quot;, &quot;Contestant&quot;].\nThe first 4 words are [&quot;Hello&quot;, &quot;how&quot;, &quot;are&quot;, &quot;you&quot;].\nHence, you should return &quot;Hello how are you&quot;.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = &quot;What is the solution to this problem&quot;, k = 4\n<strong>Output:</strong> &quot;What is the solution&quot;\n<strong>Explanation:</strong>\nThe words in s are [&quot;What&quot;, &quot;is&quot; &quot;the&quot;, &quot;solution&quot;, &quot;to&quot;, &quot;this&quot;, &quot;problem&quot;].\nThe first 4 words are [&quot;What&quot;, &quot;is&quot;, &quot;the&quot;, &quot;solution&quot;].\nHence, you should return &quot;What is the solution&quot;.</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = &quot;chopper is not a tanuki&quot;, k = 5\n<strong>Output:</strong> &quot;chopper is not a tanuki&quot;\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= s.length &lt;= 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": null,
"translatedContent": null,
"isPaidOnly": false,