• + 0 comments

    Hashmap implementation in Python In the worst case it will have an On complexity

    def has_cycle(head):
        hashmap = dict()
        while head:
            hashmap[head] = hashmap.get(head, 0) + 1
            if hashmap[head] > 1:
                return 1
            head = head.next
        return 0