C++ | Trie | Searching
\nclass Solution {\npublic:\n    class Trie {\n    public:\n        Trie() {\n            cnt = 0;\n            for(int i=0;i<26;i++){\n                this->ne
```\nclass Solution {\npublic:\n    class Trie {\n    public:\n        Trie() {\n            cnt = 0;\n            for(int i=0;i<26;i++){\n                this->next[i] = NULL;\n            }\n        }\n        void insert(string word, Trie* root) {\n            Trie* node = root;\n            int i = 0;\n            for (char ch : word) {\n                ch -= \'a\';\n                if (!node->next[ch]) { node->next[ch] = new Trie(); }\n                node->next[ch]->cnt++;\n                node = node->next[ch];\n                i++;\n            }\n        }\n\n        int search(char ch, Trie* node) {\n            return node->next[ch-\'a\']->cnt;\n        }\n\n        Trie* next[26] = {};\n        int cnt;\n    };\n    vector<int> sumPrefixScores(vector<string>& words) {\n        Trie t;\n        Trie *root = new Trie();\n        int n = words.size();\n        for(int i=0;i<n;i++){\n            t.insert(words[i], root);\n        }\n        vector<int> ans;\n        for(int i=0;i<n;i++){\n            string cur = "";\n            int c = 0;\n            Trie *node = root;\n            for(int j=0;j<words[i].length();j++){\n                c += t.search(words[i][j], node);;\n                if(node->next[words[i][j]-\'a\'] == NULL) break;\n                node = node->next[words[i][j]-\'a\'];\n            }\n            ans.push_back(c);\n        }\n        return ans;\n    }\n};\n\n```
['String', 'Trie', 'C']