leetcode/src/s0024_swap_nodes_in_pairs.cpp
2022-11-30 18:20:36 +08:00

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;
}