Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RakhmedovRS/d25842ef37c339e6260ef50097713e84 to your computer and use it in GitHub Desktop.
Save RakhmedovRS/d25842ef37c339e6260ef50097713e84 to your computer and use it in GitHub Desktop.
/**
* Returns if there is any word in the trie that starts with the given prefix.
*/
public boolean startsWith(String prefix)
{
TrieNode current = root;
for (char ch : prefix.toCharArray())
{
int pos = ch - 'a';
if (current == null || !current.chars[pos])
{
return false;
}
current = current.children[pos];
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment