Python solution using dictionary.


  • 0
    S

    '''
    def detectCycle(self, head):
    """
    :type head: ListNode
    :rtype: ListNode
    """
    node_dict={}

        while head:
            if head in node_dict:
                return head
            else:
                node_dict[head]=1
                head= head.next 
                
        return None
    

    '''


Log in to reply
 

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