1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/翻转单词顺序 [fan-zhuan-dan-ci-shun-xu-lcof].html
2022-03-29 12:43:11 +08:00

38 lines
1.6 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变。为简单起见,标点符号和普通字母一样处理。例如输入字符串&quot;I am a student. &quot;,则输出&quot;student. a am I&quot;</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong> &quot;<code>the sky is blue</code>&quot;
<strong>输出:&nbsp;</strong>&quot;<code>blue is sky the</code>&quot;
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong> &quot; &nbsp;hello world! &nbsp;&quot;
<strong>输出:&nbsp;</strong>&quot;world! hello&quot;
<strong>解释: </strong>输入字符串可以在前面或者后面包含多余的空格,但是反转后的字符不能包括。
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong> &quot;a good &nbsp; example&quot;
<strong>输出:&nbsp;</strong>&quot;example good a&quot;
<strong>解释: </strong>如果两个单词间有多余的空格,将反转后单词间的空格减少到只含一个。
</pre>
<p>&nbsp;</p>
<p><strong>说明:</strong></p>
<ul>
<li>无空格字符构成一个单词。</li>
<li>输入字符串可以在前面或者后面包含多余的空格,但是反转后的字符不能包括。</li>
<li>如果两个单词间有多余的空格,将反转后单词间的空格减少到只含一个。</li>
</ul>
<p><strong>注意:</strong>本题与主站 151 题相同:<a href="https://leetcode-cn.com/problems/reverse-words-in-a-string/">https://leetcode-cn.com/problems/reverse-words-in-a-string/</a></p>
<p><strong>注意:</strong>此题对比原题有改动</p>