This commit is contained in:
Hardik Pawar 2024-10-03 11:40:56 +05:30
parent 4aa953e400
commit 62d2412482

View File

@ -44,10 +44,10 @@ def get_middle(head: Node | None) -> Node | None:
if head is None or head.next is None:
return head
slow = head # one node at a time
slow: Node | None = head # one node at a time
fast = head # two nodes at a time
while fast.next and fast.next.next:
slow: Node | None = slow.next
slow = slow.next
fast = fast.next.next
return slow