标签:nod imu mini char mic min new t iter 图片
class TrieNode
{
public:
map<char, TrieNode*> children;
};
class Solution {
public:
void GetNum(TrieNode * node, int num, int& count)
{
if (node == NULL || node->children.size() == 0)
{
count += num + 1;
return;
}
for (map<char, TrieNode*>::iterator itor = node->children.begin(); itor != node->children.end(); itor++)
{
GetNum(itor->second, 1 + num, count );
}
}
int minimumLengthEncoding(vector<string>& words)
{
TrieNode* root = new TrieNode();
TrieNode* temp;
for (string s : words)
{
temp = root;
for (int i = s.size() - 1; i >= 0; i--)
{
if (temp->children[s[i]] == NULL)
{
temp->children[s[i]] = new TrieNode();
}
temp = temp->children[s[i]];
}
}
int count = 0;
GetNum(root, 0, count);
return count;
}
};
标签:nod imu mini char mic min new t iter 图片
原文地址:https://www.cnblogs.com/woodjay/p/12601358.html