public ListNode swapPairs(ListNode head) {// 边界条件if (head == null || head.next == null) {return head;}// 第三个节点ListNode third = head.next.next;// 新头节点指向原头节点的下一个节点ListNode newHead = head.next;// 新头节点的下一个节点指向原头节点newHead.next = head;// 递归以上步骤head.next = swapPairs(third);// 返回新的链表return newHead;}
