From ac675350005c49ed0fc706c5f47cb0b99dd050b0 Mon Sep 17 00:00:00 2001 From: Vaishnavi Gupta <113535692+Vaishnavi2445@users.noreply.github.com> Date: Mon, 10 Oct 2022 23:37:24 +0530 Subject: [PATCH] Create Middle of Linked List.cpp --- LinkedList/Middle of Linked List.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 LinkedList/Middle of Linked List.cpp diff --git a/LinkedList/Middle of Linked List.cpp b/LinkedList/Middle of Linked List.cpp new file mode 100644 index 0000000..c9be828 --- /dev/null +++ b/LinkedList/Middle of Linked List.cpp @@ -0,0 +1,14 @@ +class Solution { +public: + ListNode* middleNode(ListNode* head) { + if(head==NULL){ + return head; + } + ListNode *slow=head, *fast=head; + while(fast!=nullptr && fast->next!=nullptr){ + slow=slow->next; + fast=fast->next->next; + } + return slow; + } +};