leetcode/src/s0024_swap_nodes_in_pairs.cpp

12 lines
270 B
C++
Raw Normal View History

2022-11-14 03:57:10 +00:00
#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;
}