Last updated 1 year ago
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)