class Solution {
//需要画出链表图确定连接顺序
public ListNode swapPairs(ListNode head) {
ListNode dummy = new ListNode(-1);
dummy.next = head;
for (ListNode p = dummy; p.next != null && p.next.next != null;) {
ListNode a = p.next;
ListNode b = a.next;
p.next = b;
a.next = b.next;
b.next = a;
p = a;
}
return dummy.next;
}
}