Fast & Slow pointers||0ms beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nUse 2 pointer.\nOne fast, one slow. Move fast 2 moves & slow 1 move in each step.\n# Ap
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse 2 pointer.\nOne fast, one slow. Move fast 2 moves & slow 1 move in each step.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUntil fast reaches the end, return slow if fast->next is NULL, otherwise slow->next\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n# 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        ListNode *fast=head, *slow=head;\n        while(fast->next&& fast->next->next){\n            fast=fast->next->next;\n            slow=slow->next;\n        }\n       return (fast->next) ? slow->next:slow;\n             \n    }\n};\n```
['Linked List', 'Two Pointers', 'C++']