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.
when you are searching through a tire tree, you should be able to detect whether the current path contains a prefix or the current string you are searching is a prefix of another string.
// if any prefix existing on this pathboolcheckPrefix(string&word,TrieNode*node){TrieNode*current=node;for(charch:word){ch-='a';if(!current->children[ch])break;current=current->children[ch];if(current->isEnd)returntrue;}returnfalse;}// if the current string is a prefix of other stringboolisPrefix(string&word,TrieNode*node){TrieNode*current=node;for(charch:word){ch-='a';if(!current->children[ch])returnfalse;current=current->children[ch];}for(auto&next:current->children){if(next)returntrue;}returnfalse;}
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 →
when you are searching through a tire tree, you should be able to detect whether the current path contains a prefix or the current string you are searching is a prefix of another string.