标签:next list ret head 链表 solution return new swap
class Solution {
public ListNode swapPairs(ListNode head) {
ListNode dummy = new ListNode(-1);
ListNode p = dummy;
dummy.next = head;
while(p != null && p.next !=null && p.next.next != null){
ListNode a = p.next, b = a.next;
p.next = b;
a.next = b.next;
b.next = a;
p = a;
}
return dummy.next;
}
}
标签:next list ret head 链表 solution return new swap
原文地址:https://www.cnblogs.com/zykBlog/p/13950856.html