4
vector<TrieNode *> children;7
children = vector<TrieNode *>(26, NULL);15
root = new TrieNode();18
void insert(string &word, bool &isSuffix) {20
for (int i = 0; i < word.size(); i++) {21
int index = word[i] - 'a';23
// If new node is needed to be inserted for this word, then this word24
// can't be suffix of some other word.25
if (cur->children[index] == NULL) {27
cur->children[index] = new TrieNode();29
cur = cur->children[index];37
int minimumLengthEncoding(vector<string> &words) {38
sort(words.begin(), words.end(), [](string &a, string &b) { return a.size() > b.size(); });41
Trie *trie = new Trie();43
for (auto word : words) {44
reverse(word.begin(), word.end());45
bool wordIsSuffix = true;46
trie->insert(word, wordIsSuffix);47
// If word is not suffix of some other word, it needs to be added49
if (!wordIsSuffix) res += word.size() + 1; //+1 for '#'