Python Trie straightforward solution
Standard implementation of the Trie, but save the length of the word that is continuousely building when inserting the word.\n\n\nclass TrieNode:\n    def __ini
Standard implementation of the Trie, but save the length of the word that is continuousely building when inserting the word.\n\n```\nclass TrieNode:\n    def __init__(self):\n        self.children = defaultdict(TrieNode)\n        self.word = None  # Record the built word for the current node\n        self.length = 0  # Record the continue length of the build word\n\nclass Trie:\n    def __init__(self):\n        self.root = TrieNode()\n        self.max_length = -1  # the max length of the word in the entire words list\n        self.word = None  # the resulting word\n    \n    def insert(self, word):\n        current = self.root\n        word_length = 1\n        for letter in word:\n            if current.word:\n                word_length += 1\n            else:\n                # Reset length if one character is skipped\n                word_length = 1\n            current = current.children[letter]\n        current.word = word\n        current.length = word_length if word_length == len(word) else 1\n        \n        if current.length > self.max_length:\n            self.max_length = current.length\n            self.word = word\n        elif current.length == self.max_length:\n            self.word = min(word, self.word)\n        \nclass Solution:\n    def longestWord(self, words: List[str]) -> str:\n        tree = Trie()\n        [tree.insert(word) for word in sorted(words)]  # Have to sort to make sure the word is built in order\n        \n        return tree.word\n```\n
['Trie', 'Python', 'Python3']