class Trie
{
Map child = new HashMap<>();
boolean isWord;
public Trie()
{
isWord = false;
}
public void insert(String word)
{
Trie root = this;
for (int i = 0; i < word.length(); i ++)
{
char c = word.charAt(i);
if (root.child.containsKey(c) == false)
root.child.put(c, new Trie());
root = root.child.get(c);
}
root.isWord = true;
}
public boolean search(String word)
{
Trie root = this;
for (int i = 0; i < word.length(); i ++)
{
char c = word.charAt(i);
if (root.child.containsKey(c) == false)
return false;
root = root.child.get(c);
}
return root.isWord == true;
}
public boolean startsWith(String prefix)
{
Trie root = this;
for (int i = 0; i < prefix.length(); i ++)
{
char c = prefix.charAt(i);
if (root.child.containsKey(c) == false)
return false;
root = root.child.get(c);
}
return true;
}
}