leetcode/src/s0024_swap_nodes_in_pairs.cpp

12 lines
277 B
C++
Raw Normal View History

2022-11-14 03:57:10 +00:00
#include "s0024_swap_nodes_in_pairs.hpp"
2022-11-30 10:20:36 +00:00
ListNode* S0024::swapPairs(ListNode* head) {
2022-11-14 03:57:10 +00:00
if (head == nullptr || head->next == nullptr) {
return head;
}
ListNode *newHead = head->next;
head->next = swapPairs(newHead->next);
newHead->next = head;
return newHead;
}