1.描述
给一个链表,两两交换其中的节点,然后返回交换后的链表。
样例
样例 1:
输入:1->2->3->4->null
输出:2->1->4->3->null
样例 2:
输入:5->null
输出:5->null
2.代码
ListNode *swapPairs(ListNode *head) {
if (!head) return NULL;
if (!head->next) return head;
ListNode *temp = head->next;
head->next = swapPairs(temp->next);
temp->next = head;
return temp;
}