• + 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...