3
private Node[] children;7
children = new Node[26];8
Arrays.fill(children, null);11
public boolean getFlag() {15
public Node getChild(int index) {16
return children[index];19
public boolean hasChild(int index) {20
return children[index] != null;23
public void setFlag(boolean flag) {27
public void makeChild(int index) {28
children[index] = new Node();39
public int addWord(String word) {45
for (int i = word.length() - 1; i >= 0; --i) {46
int index = (int) word.charAt(i) - 97;48
if (!node.hasChild(index)) {50
node.makeChild(index);53
node = node.getChild(index);56
count -= word.length() - i + 1;58
if (i == 0) flag = false;62
if (!flag) node.setFlag(true);64
return flag ? count : count + 1 + word.length();69
public int minimumLengthEncoding(String[] words) {70
Trie trie = new Trie();73
for (String word : words) {74
size += trie.addWord(word);