Python intuitive solution using dictionary
The basic idea here is very simple: we construct a dictionary, whose key is the length of the given words, and the value is a list containing the words with the
The basic idea here is very simple: we construct a dictionary, whose key is the length of the given words, and the value is a list containing the words with the same length specified in the key. And when we search a word (say word "hello") in the magic dictionary, we only need to check those words in dic[len("hellow")], ( named candi in my code). Simple and quite intuitive but beat 90% :-)\n\n```\nclass MagicDictionary(object):\n\n    def __init__(self):\n        """\n        Initialize your data structure here.\n        """\n        self.wordsdic={}\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 i in dict:\n            self.wordsdic[len(i)]=self.wordsdic.get(len(i),[])+[i]\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        for candi in self.wordsdic.get(len(word),[]):\n                countdiff=0\n                for j in range(len(word)):\n                    if candi[j]!=word[j]:\n                        countdiff+=1\n                if countdiff==1:\n                    return True\n        return False\n                    \n        \n\n\n# Your MagicDictionary object will be instantiated and called as such:\n# obj = MagicDictionary()\n# obj.buildDict(dict)\n# param_2 = obj.search(word)\n```
[]