思路:
定义三个指针,其中一个临时指针,进行交换两个节点的值,重新给临时指针赋值,移动链表
class Solution {public ListNode swapPairs(ListNode head) {ListNode pre = new ListNode(0,head);ListNode temp = pre;while(temp.next != null && temp.next.next != null){ListNode start = temp.next,end = temp.next.next;temp.next = start.next;start.next = end.next;end.next = start;temp = start;}return pre.next;}
}