Linked List Cycle II (LC-0142)
class Solution:
def detectCycle(self, head):
fast = slow = head
start = True
while (fast and fast.next) and (start or slow != fast):
if start: start = False
fast = fast.next.next
slow = slow.next
if start or (fast != slow):
return None
slow1 = head
slow2 = fast
while slow1 != slow2:
slow1 = slow1.next
slow2 = slow2.next
return slow1