Created
July 17, 2022 22:31
-
-
Save RakhmedovRS/d25842ef37c339e6260ef50097713e84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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