Clean JAVA code(optimized) || 0ms-100%Beats
Intuition: IF A\'s speed is double as of B\'s then when A will reach the end B will be at middle.\n Describe your first thoughts on how to solve this problem. \
# Intuition: IF A\'s speed is double as of B\'s then when A will reach the end B will be at middle.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\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# Code\n```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode() {}\n *     ListNode(int val) { this.val = val; }\n *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n    public ListNode middleNode(ListNode head) {\n          \n        if(head==null || head.next==null) return head;\n        \n        ListNode slow = head;\n        ListNode fast = head;\n        while(fast!=null && fast.next!=null){\n            slow = slow.next;\n            fast = fast.next.next;\n        }\n        return slow;\n    }\n}\n```
['Java']