12 lines
270 B
C++
12 lines
270 B
C++
|
#include "s0024_swap_nodes_in_pairs.hpp"
|
||
|
|
||
|
ListNode* 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;
|
||
|
}
|