1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/重排链表 [LGjMqU].html
2022-03-29 12:43:11 +08:00

40 lines
1.5 KiB
HTML

<p>给定一个单链表 <code>L</code><em> </em>的头节点 <code>head</code> ,单链表 <code>L</code> 表示为:</p>
<p><code>&nbsp;L<sub>0&nbsp;</sub>&rarr; L<sub>1&nbsp;</sub>&rarr; &hellip; &rarr; L<sub>n-1&nbsp;</sub>&rarr; L<sub>n&nbsp;</sub></code><br />
请将其重新排列后变为:</p>
<p><code>L<sub>0&nbsp;</sub>&rarr;&nbsp;L<sub>n&nbsp;</sub>&rarr;&nbsp;L<sub>1&nbsp;</sub>&rarr;&nbsp;L<sub>n-1&nbsp;</sub>&rarr;&nbsp;L<sub>2&nbsp;</sub>&rarr;&nbsp;L<sub>n-2&nbsp;</sub>&rarr; &hellip;</code></p>
<p>不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<p><img alt="" src="https://pic.leetcode-cn.com/1626420311-PkUiGI-image.png" style="width: 240px; " /></p>
<pre>
<strong>输入: </strong>head = [1,2,3,4]
<strong>输出: </strong>[1,4,2,3]</pre>
<p><strong>示例 2:</strong></p>
<p><img alt="" src="https://pic.leetcode-cn.com/1626420320-YUiulT-image.png" style="width: 320px; " /></p>
<pre>
<strong>输入: </strong>head = [1,2,3,4,5]
<strong>输出: </strong>[1,5,2,4,3]</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>链表的长度范围为 <code>[1, 5 * 10<sup>4</sup>]</code></li>
<li><code>1 &lt;= node.val &lt;= 1000</code></li>
</ul>
<p>&nbsp;</p>
<p><meta charset="UTF-8" />注意:本题与主站 143&nbsp;题相同:<a href="https://leetcode-cn.com/problems/reorder-list/">https://leetcode-cn.com/problems/reorder-list/</a>&nbsp;</p>