(ListNode head)
| 20 | // } |
| 21 | |
| 22 | public ListNode swapPairs(ListNode head) { |
| 23 | ListNode preHead = new ListNode(0), cur = preHead; |
| 24 | preHead.next = head; |
| 25 | while (cur.next != null && cur.next.next != null) { |
| 26 | ListNode temp = cur.next.next; |
| 27 | cur.next.next = temp.next; |
| 28 | temp.next = cur.next; |
| 29 | cur.next = temp; |
| 30 | cur = cur.next.next; |
| 31 | } |
| 32 | return preHead.next; |
| 33 | } |
| 34 | |
| 35 | public static void main(String[] args) { |
| 36 | Solution solution = new Solution(); |