From 2686886ee3bb34ef9efc1890dcc2f8b606511d14 Mon Sep 17 00:00:00 2001 From: Akash Singh Date: Sat, 15 Oct 2022 12:57:11 +0530 Subject: [PATCH] Added CPP code of swap nodes in pairs --- 24.swap nodes in pairs.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 24.swap nodes in pairs.cpp diff --git a/24.swap nodes in pairs.cpp b/24.swap nodes in pairs.cpp new file mode 100644 index 0000000..faa6034 --- /dev/null +++ b/24.swap nodes in pairs.cpp @@ -0,0 +1,12 @@ +class Solution { +public: + ListNode* swapPairs(ListNode* head) { + if(!head || !head->next) return head; + ListNode* temp; + temp = head->next; + head->next = swapPairs(head->next->next); + temp->next = head; + + return temp; + } +}; \ No newline at end of file