python trie solution
sort words by word length, so that short words are inserted firstly\n* insert words into trie one by one, if all of sub-words already exist in trie, return Fals
* sort words by word length, so that short words are inserted firstly\n* insert words into trie one by one, if all of sub-words already exist in trie, return False.\n\n```\nclass TrieNode:\n    def __init__(self):\n        self.isWord = False\n        self.children = collections.defaultdict(TrieNode)\n\nclass Trie:\n    def __init__(self):\n        self.root = TrieNode()\n        \n    def insert(self, word):\n        node = self.root\n        for i, c in enumerate(word):\n            node = node.children[c]\n            if node.isWord:\n                if self.exists(word[i+1:]):\n                    return False\n                else:\n                    continue\n        node.isWord = True\n        return True\n    \n    def exists(self, word):\n        node = self.root\n        for i, c in enumerate(word):\n            if c in node.children:\n                node = node.children[c]\n                if node.isWord:\n                    if i == len(word)-1 or self.exists(word[i+1:]):\n                        return True\n                    else:\n                        continue\n            else:\n                return False\n\nclass Solution:\n    def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n        \n        trie = Trie()\n        \n        return [word for word in sorted(words, key=len) if not trie.insert(word)]
[]