24. 两两替换链表中的节点
1. 双指针法
class Solution {public ListNode swapPairs(ListNode head) {ListNode pre = new ListNode(-1,head),temp = pre;
while(temp.next != null && temp.next.next != null){
ListNode first = temp.next;
ListNode second = temp.next.next;
first.next = second.next;
second.next = first;
temp.next = second;
temp = first;
}
return pre.next;
}
}