/**
* @Description 一遍过了,可以奥
* @Date 2022/1/19 11:09 下午
* @Author wuqichuan@zuoyebang.com
**/
public class Solution {
public ListNode swapPairs(ListNode head) {
ListNode dummyHead = new ListNode();
dummyHead.next = head;
ListNode pre = dummyHead;
while (pre.next != null && pre.next.next != null) {
ListNode node1 = pre.next;
ListNode node2 = pre.next.next;
ListNode node2Next = node2.next;
node1.next = node2Next;
pre.next = node2;
node2.next = node1;
pre = node1;
}
return dummyHead.next;
}
}