1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-02-04 14:40:27 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/字符串中的单词反转 [fan-zhuan-dan-ci-shun-xu-lcof].html

48 lines
1.7 KiB
HTML
Raw Normal View History

2023-12-09 18:53:53 +08:00
<p>你在与一位习惯从右往左阅读的朋友发消息,他发出的文字顺序都与正常相反但单词内容正确,为了和他顺利交流你决定写一个转换程序,把他所发的消息 <code>message</code> 转换为正常语序。</p>
<p>注意:输入字符串 <code>message</code> 中可能会存在前导空格、尾随空格或者单词间的多个空格。返回的结果字符串中,单词间应当仅用单个空格分隔,且不包含任何额外的空格。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong> message = "<code>the sky is blue</code>"
<strong>输出:&nbsp;</strong>"<code>blue is sky the</code>"
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong> message = " &nbsp;hello world! &nbsp;"
<strong>输出:&nbsp;</strong>"world! hello"
<strong>解释: </strong>输入字符串可以在前面或者后面包含多余的空格,但是反转后的字符不能包括。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong> message = "a good &nbsp; example"
<strong>输出:&nbsp;</strong>"example good a"
<strong>解释: </strong>如果两个单词间有多余的空格,将反转后单词间的空格减少到只含一个。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= message.length &lt;= 10^4</code></li>
<li><code>message</code> 中包含英文大小写字母、空格和数字</li>
<li><code>message</code> 中至少有一个单词</li>
<li>&nbsp;</li>
</ul>
<p><strong>注意:</strong></p>
<ul>
<li>本题与主站 151 题相同:<a href="https://leetcode-cn.com/problems/reverse-words-in-a-string/">https://leetcode-cn.com/problems/reverse-words-in-a-string/</a></li>
</ul>
<p>&nbsp;</p>