From f5b1fe409805ec935c89e1c119e01127a6bf573d Mon Sep 17 00:00:00 2001 From: Kunal Chauhan <87843911+Kunal-Chauhan7@users.noreply.github.com> Date: Sun, 9 Oct 2022 16:16:15 +0530 Subject: [PATCH] Added Solution Of reverse Linked list This solution is written in c++ and solves this problem:- https://leetcode.com/problems/reverse-linked-list --- ReverseLinkedList.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 ReverseLinkedList.cpp diff --git a/ReverseLinkedList.cpp b/ReverseLinkedList.cpp new file mode 100644 index 0000000..ddeaba0 --- /dev/null +++ b/ReverseLinkedList.cpp @@ -0,0 +1,16 @@ +class Solution { +public: + ListNode* reverseList(ListNode* head) { + ListNode* current = head; + ListNode *prev = NULL, *next = NULL; + + while (current != NULL) { + next = current->next; + current->next = prev; + prev = current; + current = next; + } + head = prev; + return head; + } +};