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