Skip to content

Instantly share code, notes, and snippets.

@Khamies
Last active March 25, 2023 22:23
Show Gist options
  • Save Khamies/489356d8b331a0ff1fe96b239048a7f4 to your computer and use it in GitHub Desktop.
Save Khamies/489356d8b331a0ff1fe96b239048a7f4 to your computer and use it in GitHub Desktop.
def get_pointers_meetingPoint(head):
slow = head
fast = head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
if slow == fast:
return slow
return None
def get_cycle_start(head, meeting_point):
p = head
q = meeting_point
while p != q:
p = p.next
q = q.next
return p
if __name__ == '__main__':
meeting_point = get_pointers_meetingPoint(head)
if not meeting_point:
return None
else:
return get_cycle_start(head, meeting_point)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment