python soln


  • 0
    I
    class Solution(object):
        def detectCycle(self, head):
            """
            :type head: ListNode
            :rtype: ListNode
            """
            slow = head
            fast = head
            
            while fast and fast.next:
                slow = slow.next
                fast = fast.next.next
                if fast == slow:
                    temp = head
                    while temp != slow:
                        temp = temp.next
                        slow = slow.next
                    return temp
                
            return None

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.