Rabbit-Turtle Method | Explained Theory | CPP | O(N) | Easy
Approach  : Rabbit-Turtle Method \nHere we will traverse two pointers from Head of Singly Linked List, where Slow pointer will Move one position at time and fas
# Approach  : Rabbit-Turtle Method \nHere we will traverse two pointers from Head of Singly Linked List, where Slow pointer will Move one position at time and fast pointer will move two positions at time. When fast pointer Reaches Last or ( Last-1(For odd input) position our slow will be in middle, Simply return middle as we have slow pointer pointing on.\nSlow Pointer Worked as Turtle\nFast Pointer Worked ad Rabbit.\nReference From Famous Race story of Rabbit and Turtle :)  \n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# CPP Code\n```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* middleNode(ListNode* head) {\n\tListNode *slow = head, *fast = head;\n\twhile (fast && fast->next) {\n\t    slow = slow->next;\n\t    fast = fast->next->next;\n\t}\n\treturn slow;\n    }\n};\n```\n# Upvote if it Helped :)
['C++']