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.
Use Trie with python and create find_prefix function.
In find_prefix function, consider the inserting order. For example : words_1 = ["dogfood","dog"] or words_2= ["dog","dogfood"].
In word_1, the length of "dogfood" is longer than "dog", so that the current.is_word_end is not working. Thus, we have the return True outside the loop check.
In word_2, the length of "dog" is shorter than "dogfood", When we check "dogfood", we will find "dog". Then we get the current.is_word_end is True.
Besides, if there is not any same char in child node then we return False.
No Prefix Set
You are viewing a single comment's thread. Return to all comments →
Use Trie with python and create find_prefix function. In find_prefix function, consider the inserting order. For example :
words_1 = ["dogfood","dog"]
orwords_2= ["dog","dogfood"]
. In word_1, the length of "dogfood" is longer than "dog", so that thecurrent.is_word_end
is not working. Thus, we have thereturn True
outside the loop check. In word_2, the length of "dog" is shorter than "dogfood", When we check "dogfood", we will find "dog". Then we get thecurrent.is_word_end
is True.Besides, if there is not any same char in child node then we
return False
.