Sort by

recency

|

1342 Discussions

|

  • + 0 comments

    Description is BS!

    Head refers to the list of nodes 1 -> 2 -> 3 -> 1 -> NULL There is a cycle where node 3 points back to node 1, so return .

    Ah??? If there is a cycle then there will be no NULL and it should be like so:

    1 -> 2 -> 3 -> 1 -> 2 ... etc

  • + 0 comments

    This is not a well written problem. This is bad.

  • + 0 comments

    Hacky solution for the lulz:

    def has_cycle(head):
        c = 0
        while head:
            head = head.next
            c += 1
            if c > 1000:
                return 1
        return 0
    
  • + 0 comments
     if head is None:
            return False
        
        slow = fast = head
        
        while fast is not None and fast.next is not None:
            slow = slow.next
            fast = fast.next.next
            
            if slow == fast:
                return True
        return False
    
  • + 0 comments

    in Typescript most of the required starting code is not there