Here is my easy to understand C++ sloution
\nclass Solution {\n    \npublic:\n    struct TrieNode{\n    struct TrieNode *child[26];\n    bool eow;\n};\nstruct TrieNode *getNode(void)\n{\n    struct TrieN
```\nclass Solution {\n    \npublic:\n    struct TrieNode{\n    struct TrieNode *child[26];\n    bool eow;\n};\nstruct TrieNode *getNode(void)\n{\n    struct TrieNode *node = new TrieNode;\n    node->eow = false;\n    for(int i=0;i<26;i++)\n    {\n        node->child[i] = NULL;\n    }\n    return node;\n}\nbool insert(struct TrieNode *root, string word)\n{\n    struct TrieNode *pcrawl = root;\n    int count = 0;\n    for(int i=0;i<word.length();i++)\n    {\n        int index = word[i] - \'a\';\n        if(!pcrawl->eow)\n            count++;\n        if(!pcrawl->child[index])\n        {\n            pcrawl->child[index] = getNode();\n        }\n        pcrawl = pcrawl->child[index];\n        \n    }\n    pcrawl->eow = true;\n    if(count == 1)\n        return true;\n    else\n        return false;\n}\n    string longestWord(vector<string>& words) {\n        int l = words.size();\n        if(l == 1)\n            return words[0];\n        if(l==0)\n            return "";\n        struct TrieNode *root = getNode();\n        sort(words.begin(),words.end());\n        int count = 0;\n        string str = "";\n        for(int i=0;i<l;i++)\n        {\n            bool valid = insert(root, words[i]);\n            if(valid)\n            {\n                if(words[i].length() > str.length())\n                {\n                    str = words[i];\n                }\n            }\n        }\n        return str;\n    }\n};\n```
['Trie']