Just a dictionary
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\nM is nu
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\nM is number of strings and N is the length of String\nBuild time\n- Time complexity:\n    $$O(m*n)$$\n\n\n- search time\n$$O(n*n)$$\n\n- Space complexity:\n$$O(m*n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass MagicDictionary {\n\n    private Node root;\n    public MagicDictionary() {\n        root = new Node();\n    }\n    \n    public void buildDict(String[] dictionary) {\n        for(String str: dictionary) {\n            addString(root, 0, str);\n        }\n    }\n\n    private void addString(Node node, int index, String str) {\n        if(str.length() > index) {\n            char ch = str.charAt(index);\n            if(!node.hasChar(ch)) {\n                node.addChar(ch);\n            }\n            addString(node.getChar(ch), ++index, str);\n        } else {\n            node.setWord();\n        }\n    }\n    \n    public boolean search(String searchWord) {\n        return search(searchWord, 0, this.root, false);\n    }\n\n    private boolean search(String str, int index, Node node, boolean charChanged) {\n        if(index < str.length()) {\n            char ch = str.charAt(index);\n            if(charChanged) {\n               return node.hasChar(ch) && search(str, index+1, node.getChar(ch), true);\n            }  else {\n                boolean found = false;\n                for(char key : node.getAllChars().keySet()) {\n                    if(!found && key != ch) {\n                        found = search(str, index+1, node.getChar(key), true);\n                    }\n                }\n                return found || node.hasChar(ch) && search(str, index+1, node.getChar(ch), false);\n            }\n            \n        } \n        return index == str.length() && charChanged && node.isWord();\n    }\n\n\n    private class Node {\n        private Map<Character, Node> chars;\n        private boolean isWord;\n\n        public Node() {\n            this.chars = new HashMap<>();\n        }\n        public boolean isWord() {\n            return this.isWord;\n        }\n\n        public void setWord(){\n            this.isWord = true;\n        }\n\n        public boolean hasChar(char ch) {\n            return chars.containsKey(ch);\n        }\n\n        public Node getChar(char ch) {\n            return this.chars.get(ch);\n        }\n\n        public void addChar(char ch) {\n            this.chars.put(ch, new Node());\n        }\n\n        public Map<Character, Node> getAllChars() {\n            return this.chars;\n        }\n\n        @Override\n        public String toString() {\n            return "Mapping: " + this.chars + " isWord: " + this.isWord;\n        }\n\n    }\n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * MagicDictionary obj = new MagicDictionary();\n * obj.buildDict(dictionary);\n * boolean param_2 = obj.search(searchWord);\n */\n```
['Java']