Class Solution

java.lang.Object
g0101_0200.s0143_reorder_list.Solution

public class Solution extends Object
143 - Reorder List.<p>Medium</p> <p>You are given the head of a singly linked-list. The list can be represented as:</p> <p>L<sub>0</sub> \u2192 L<sub>1</sub> \u2192 \u2026 \u2192 L<sub>n - 1</sub> \u2192 L<sub>n</sub></p> <p><em>Reorder the list to be on the following form:</em></p> <p>L<sub>0</sub> \u2192 L<sub>n</sub> \u2192 L<sub>1</sub> \u2192 L<sub>n - 1</sub> \u2192 L<sub>2</sub> \u2192 L<sub>n - 2</sub> \u2192 \u2026</p> <p>You may not modify the values in the list&rsquo;s nodes. Only nodes themselves may be changed.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/03/04/reorder1linked-list.jpg" alt="" /></p> <p><strong>Input:</strong> head = [1,2,3,4]</p> <p><strong>Output:</strong> [1,4,2,3]</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/03/09/reorder2-linked-list.jpg" alt="" /></p> <p><strong>Input:</strong> head = [1,2,3,4,5]</p> <p><strong>Output:</strong> [1,5,2,4,3]</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>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • reorderList

      public void reorderList(ListNode head)