标签:lan solution tno 问题 直接 new 指针 head lis
class Solution {
public ListNode swapPairs(ListNode head) {
if(head == null) return null;
if(head.next == null) return head;
ListNode newHead = head.next;
ListNode p1 = new ListNode(0, head);
ListNode p2 = head;
while(p2 != null && p2.next != null){
ListNode p3 = p2.next;
p1.next = p3;
p2.next = p3.next;
p3.next = p2;
p1 = p2;
p2 = p1.next;
}
return newHead;
}
}
标签:lan solution tno 问题 直接 new 指针 head lis
原文地址:https://www.cnblogs.com/xiafrog/p/14384071.html