题目:给你一个链表,两两交换其中相邻的节点,并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题(即,只能进行节点交换)。
=
public static ListNode swapPairs(ListNode head) { if(head==null||head.next==null) return head; // ListNode one=head; ListNode two=one.next; one.next=two.next; two.next=one; ListNode current=two.next.next; ListNode twotemp=null; ListNode prev_cur=two.next; while(current!=null&¤t.next!=null){ twotemp=current.next; current.next=twotemp.next; twotemp.next=current; prev_cur.next=twotemp; current=twotemp.next.next; prev_cur=twotemp.next; } return two; }
=
标签:24,力扣,ListNode,twotemp,current,two,next,链表,null From: https://www.cnblogs.com/qingmaple/p/17609165.html