|
| 1 | +<h2><a href="https://leetcode.com/problems/swap-nodes-in-pairs/">24. Swap Nodes in Pairs</a></h2><h3>Medium</h3><hr><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's nodes (i.e., only nodes themselves may be changed.)</p> |
| 2 | + |
| 3 | +<p> </p> |
| 4 | +<p><strong class="example">Example 1:</strong></p> |
| 5 | + |
| 6 | +<div class="example-block"> |
| 7 | +<p><strong>Input:</strong> <span class="example-io">head = [1,2,3,4]</span></p> |
| 8 | + |
| 9 | +<p><strong>Output:</strong> <span class="example-io">[2,1,4,3]</span></p> |
| 10 | + |
| 11 | +<p><strong>Explanation:</strong></p> |
| 12 | + |
| 13 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/swap_ex1.jpg" style="width: 422px; height: 222px;" /></p> |
| 14 | +</div> |
| 15 | + |
| 16 | +<p><strong class="example">Example 2:</strong></p> |
| 17 | + |
| 18 | +<div class="example-block"> |
| 19 | +<p><strong>Input:</strong> <span class="example-io">head = []</span></p> |
| 20 | + |
| 21 | +<p><strong>Output:</strong> <span class="example-io">[]</span></p> |
| 22 | +</div> |
| 23 | + |
| 24 | +<p><strong class="example">Example 3:</strong></p> |
| 25 | + |
| 26 | +<div class="example-block"> |
| 27 | +<p><strong>Input:</strong> <span class="example-io">head = [1]</span></p> |
| 28 | + |
| 29 | +<p><strong>Output:</strong> <span class="example-io">[1]</span></p> |
| 30 | +</div> |
| 31 | + |
| 32 | +<p><strong class="example">Example 4:</strong></p> |
| 33 | + |
| 34 | +<div class="example-block"> |
| 35 | +<p><strong>Input:</strong> <span class="example-io">head = [1,2,3]</span></p> |
| 36 | + |
| 37 | +<p><strong>Output:</strong> <span class="example-io">[2,1,3]</span></p> |
| 38 | +</div> |
| 39 | + |
| 40 | +<p> </p> |
| 41 | +<p><strong>Constraints:</strong></p> |
| 42 | + |
| 43 | +<ul> |
| 44 | + <li>The number of nodes in the list is in the range <code>[0, 100]</code>.</li> |
| 45 | + <li><code>0 <= Node.val <= 100</code></li> |
| 46 | +</ul> |
0 commit comments