https://leetcode.com/problems/middle-of-the-linked-list/
class Solution: def middleNode(self, head: Optional[ListNode]) -> Optional[ListNode]: slow = fast = head while fast and fast.next: slow = slow.next fast = fast.next.next return slow
时间复杂度:O(n) 空间复杂度:O(1)
Last updated 10 months ago