12 lines
277 B
C++
12 lines
277 B
C++
#include "s0024_swap_nodes_in_pairs.hpp"
|
|
|
|
ListNode* S0024::swapPairs(ListNode* head) {
|
|
if (head == nullptr || head->next == nullptr) {
|
|
return head;
|
|
}
|
|
ListNode *newHead = head->next;
|
|
head->next = swapPairs(newHead->next);
|
|
newHead->next = head;
|
|
return newHead;
|
|
}
|