Class Solution

java.lang.Object
g0001_0100.s0024_swap_nodes_in_pairs.Solution

public class Solution extends Object
24 - Swap Nodes in Pairs.<p>Medium</p> <p>Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list&rsquo;s nodes (i.e., only nodes themselves may be changed.)</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/10/03/swap_ex1.jpg" alt="" /></p> <p><strong>Input:</strong> head = [1,2,3,4]</p> <p><strong>Output:</strong> [2,1,4,3]</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> head = []</p> <p><strong>Output:</strong> []</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> head = [1]</p> <p><strong>Output:</strong> [1]</p> <p><strong>Constraints:</strong></p> <ul> <li>The number of nodes in the list is in the range <code>[0, 100]</code>.</li> <li><code>0 <= Node.val <= 100</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details