Python - really easy to understand (Explanations)
Instead of using a Trie, we can make a dictionary with the lengths of the words as the key and the list of all the words with the length as values, something li
Instead of using a Trie, we can make a dictionary with the lengths of the words as the key and the list of all the words with the length as values, something like this:\n```defaultdict(<type \'list\'>, {8: [u\'leetcode\'], 5: [u\'hello\', u\'hallo\']})```\n\nNow, we simply have to go through each word in the dictionary, whise length matches with the incoming word and see the number of same characters, if that is equal to the length - 1, then we get our answer. \nNOTE: We cannot use a set here, because the order of the words matter. Hence, need to use a list only.\nThe worst case time complexity will be O(n*|word|), but that will rarely occur, since we are negating all the words with the different lengths in a single strike.\nThe code is as below:\n\n```from collections import defaultdict\n\nclass MagicDictionary(object):\n\n    def __init__(self):\n        """\n        Initialize your data structure here.\n        """\n        self.d = defaultdict(list)\n\n    def buildDict(self, dict):\n        """\n        Build a dictionary through a list of words\n        :type dict: List[str]\n        :rtype: void\n        """\n        for word in dict:\n            length = len(word)\n            self.d[length].append(word)\n        print(self.d)\n\n    def search(self, word):\n        """\n        Returns if there is any word in the trie that equals to the given word after modifying exactly one character\n        :type word: str\n        :rtype: bool\n        """\n        lenn = len(word)\n        \n        if lenn not in self.d:\n            return False\n        \n        for w in self.d[lenn]:\n            count = 0\n            i = 0\n            while i< lenn:\n                if w[i] == word[i]:\n                    count += 1\n                i += 1\n            if count == lenn-1:\n                return True\n        return False\n```\n
[]