|
1 |
| -# [186. 翻转字符串里的单词 II](https://leetcode.cn/problems/reverse-words-in-a-string-ii) |
| 1 | +# [186. 反转字符串中的单词 II](https://leetcode.cn/problems/reverse-words-in-a-string-ii) |
2 | 2 |
|
3 | 3 | [English Version](/solution/0100-0199/0186.Reverse%20Words%20in%20a%20String%20II/README_EN.md)
|
4 | 4 |
|
5 | 5 | ## 题目描述
|
6 | 6 |
|
7 | 7 | <!-- 这里写题目描述 -->
|
8 | 8 |
|
9 |
| -<p>给定一个字符串,逐个翻转字符串中的每个单词。</p> |
| 9 | +<p>给你一个字符数组 <code>s</code> ,反转其中 <strong>单词</strong> 的顺序。</p> |
10 | 10 |
|
11 |
| -<p><strong>示例:</strong></p> |
| 11 | +<p><strong>单词</strong> 的定义为:单词是一个由非空格字符组成的序列。<code>s</code> 中的单词将会由单个空格分隔。</p> |
12 | 12 |
|
13 |
| -<pre><strong>输入: </strong>["t","h","e"," ","s","k","y"," ","i","s"," ","b","l","u","e"] |
14 |
| -<strong>输出: </strong>["b","l","u","e"," ","i","s"," ","s","k","y"," ","t","h","e"]</pre> |
| 13 | +<div class="original__bRMd"> |
| 14 | +<div> |
| 15 | +<p>必须设计并实现 <strong>原地</strong> 解法来解决此问题,即不分配额外的空间。</p> |
15 | 16 |
|
16 |
| -<p><strong>注意:</strong></p> |
| 17 | +<p> </p> |
| 18 | + |
| 19 | +<p><strong>示例 1:</strong></p> |
| 20 | + |
| 21 | +<pre> |
| 22 | +<strong>输入:</strong>s = ["t","h","e"," ","s","k","y"," ","i","s"," ","b","l","u","e"] |
| 23 | +<strong>输出:</strong>["b","l","u","e"," ","i","s"," ","s","k","y"," ","t","h","e"] |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p><strong>示例 2:</strong></p> |
| 27 | + |
| 28 | +<pre> |
| 29 | +<strong>输入:</strong>s = ["a"] |
| 30 | +<strong>输出:</strong>["a"] |
| 31 | +</pre> |
| 32 | + |
| 33 | +<p> </p> |
| 34 | + |
| 35 | +<p><strong>提示:</strong></p> |
17 | 36 |
|
18 | 37 | <ul>
|
19 |
| - <li>单词的定义是不包含空格的一系列字符</li> |
20 |
| - <li>输入字符串中不会包含前置或尾随的空格</li> |
21 |
| - <li>单词与单词之间永远是以单个空格隔开的</li> |
| 38 | + <li><code>1 <= s.length <= 10<sup>5</sup></code></li> |
| 39 | + <li><code>s[i]</code> 可以是一个英文字母(大写或小写)、数字、或是空格 <code>' '</code> 。</li> |
| 40 | + <li><code>s</code> 中至少存在一个单词</li> |
| 41 | + <li><code>s</code> 不含前导或尾随空格</li> |
| 42 | + <li>题目数据保证:<code>s</code> 中的每个单词都由单个空格分隔</li> |
22 | 43 | </ul>
|
23 |
| - |
24 |
| -<p><strong>进阶:</strong>使用 <em>O</em>(1) 额外空间复杂度的原地解法。</p> |
| 44 | +</div> |
| 45 | +</div> |
25 | 46 |
|
26 | 47 | ## 解法
|
27 | 48 |
|
|
0 commit comments