• + 0 comments

    Python code for Cycle detection

    **Works Totally well for all the test cases **

    def has_cycle(head):
        if not head or not head.next:
            return 0      
        p = q = head
        while(True):
            p = p.next 
            q = q.next
            q = q.next if (q) else None
            if(p and q and p != q):
                continue
            else:
                break
        if( p == q ):
            return 1    
        else:
            return 0    
    

    Upvote it if you found it pretty helpful & Do Comment below for any suggestions⛳