
思路:
定义三个指针,其中一个临时指针,进行交换两个节点的值,重新给临时指针赋值,移动链表

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;
}
}





![python的line[:-1]和line[-1]](https://img-blog.csdnimg.cn/direct/0cd795e076f745f4b34a63462fbf9da9.png)












