Sort by

recency

|

1355 Discussions

|

  • + 0 comments

    def has_cycle(head): slow = head fast = head

    while fast != None and fast.next != None:
        slow = slow.next
        fast = fast.next.next
    
        if slow == fast:
            return 1  # Cycle detected
    
    return 0  # No cycle
    
  • + 0 comments

    This was very frustrating

     C++ 20  DOES NOT HAVE  the proper boiler plate code setup for this problem.
    

    I had to use C++14

    why did you have to do this to me hackerrank T-T

  • + 0 comments

    I assumed you had to preserve the integrity of the data in the list, I did this as a joke lol

    def has_cycle(head):
        if head is None: 
            return 0
        
        while(True):
            if head.data == "foo": 
                return 1
            
            if head.next is None:
                return 0
            head.data ="foo"
            head = head.next
            
    

    Though replace foo with something cruder...

  • + 0 comments

    Isn't this part badly written?

    "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 1."

    It says there is a cycle but from 1 it points to NULL,shouldnt instead return to the first value ,as in photos?

  • + 1 comment

    Looks like someone messed up the running code?