We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
be careful with the limit memory,
can not do manual way,
only with trie on python
classTrieNode:def__init__(self):self.children={}self.is_end_of_word=FalseclassTrie:def__init__(self):self.root=TrieNode()definsert(self,word):node=self.rootforcharinword:ifcharnotinnode.children:node.children[char]=TrieNode()node=node.children[char]# If we reach a node that is the end of another word, it's a BAD SETifnode.is_end_of_word:returnFalse# Mark the end of this wordnode.is_end_of_word=True# If this word is a prefix of any existing word, it's a BAD SETifnode.children:returnFalsereturnTruedefnoPrefix(words):trie=Trie()forwordinwords:ifnottrie.insert(word):print("BAD SET")print(word)returnprint("GOOD SET")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
No Prefix Set
You are viewing a single comment's thread. Return to all comments →
be careful with the limit memory, can not do manual way, only with trie on python