mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 15:01:40 +08:00
国外版
This commit is contained in:
36
算法题(国外版)/reorder-list.html
Normal file
36
算法题(国外版)/reorder-list.html
Normal file
@@ -0,0 +1,36 @@
|
||||
<p>You are given the head of a singly linked-list. The list can be represented as:</p>
|
||||
|
||||
<pre>
|
||||
L<sub>0</sub> → L<sub>1</sub> → … → L<sub>n - 1</sub> → L<sub>n</sub>
|
||||
</pre>
|
||||
|
||||
<p><em>Reorder the list to be on the following form:</em></p>
|
||||
|
||||
<pre>
|
||||
L<sub>0</sub> → L<sub>n</sub> → L<sub>1</sub> → L<sub>n - 1</sub> → L<sub>2</sub> → L<sub>n - 2</sub> → …
|
||||
</pre>
|
||||
|
||||
<p>You may not modify the values in the list's nodes. Only nodes themselves may be changed.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/04/reorder1linked-list.jpg" style="width: 422px; height: 222px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> head = [1,2,3,4]
|
||||
<strong>Output:</strong> [1,4,2,3]
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/09/reorder2-linked-list.jpg" style="width: 542px; height: 222px;" />
|
||||
<pre>
|
||||
<strong>Input:</strong> head = [1,2,3,4,5]
|
||||
<strong>Output:</strong> [1,5,2,4,3]
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The number of nodes in the list is in the range <code>[1, 5 * 10<sup>4</sup>]</code>.</li>
|
||||
<li><code>1 <= Node.val <= 1000</code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user