Class Solution
java.lang.Object
g0301_0400.s0328_odd_even_linked_list.Solution
328 - Odd Even Linked List.<p>Medium</p>
<p>Given the <code>head</code> of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return <em>the reordered list</em>.</p>
<p>The <strong>first</strong> node is considered <strong>odd</strong> , and the <strong>second</strong> node is <strong>even</strong> , and so on.</p>
<p>Note that the relative order inside both the even and odd groups should remain as it was in the input.</p>
<p>You must solve the problem in <code>O(1)</code> extra space complexity and <code>O(n)</code> time complexity.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/03/10/oddeven-linked-list.jpg" alt="" /></p>
<p><strong>Input:</strong> head = [1,2,3,4,5]</p>
<p><strong>Output:</strong> [1,3,5,2,4]</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/03/10/oddeven2-linked-list.jpg" alt="" /></p>
<p><strong>Input:</strong> head = [2,1,3,5,6,4,7]</p>
<p><strong>Output:</strong> [2,3,6,7,1,5,4]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n ==</code>number of nodes in the linked list</li>
<li><code>0 <= n <= 10<sup>4</sup></code></li>
<li><code>-10<sup>6</sup> <= Node.val <= 10<sup>6</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
oddEvenList
-