Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save RakhmedovRS/b460db4fd040a47ca33e8afc401af7c0 to your computer and use it in GitHub Desktop.

Select an option

Save RakhmedovRS/b460db4fd040a47ca33e8afc401af7c0 to your computer and use it in GitHub Desktop.
/**
* Inserts a word into the trie.
*/
public void insert(String word)
{
TrieNode current = root;
for (char ch : word.toCharArray())
{
int pos = ch - 'a';
current.chars[pos] = true;
TrieNode next = current.children[pos];
if (next == null)
{
current.children[pos] = new TrieNode();
next = current.children[pos];
}
current = next;
}
current.isEnd = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment