class Trie {
private static final int ALPHABET_SIZE = 26;
private final Trie[] node = new Trie[ALPHABET_SIZE];
private boolean isEnd;
public void insert(String word) {
Trie temp = this;
for (char c : word.toCharArray()) {
int index = c - 'a';
if (temp.node[index] == null) {
temp.node[index] = new Trie();
}
temp = temp.node[index];
}
temp.isEnd = true;
}
public boolean search(String word) {
Trie temp = this;
for (char c : word.toCharArray()) {
int index = c - 'a';
if (temp.node[index] == null) {
return false;
}
temp = temp.node[index];
}
return temp.isEnd;
}
}