[Java] [Iterative] BFS
Seems like everybody prefers the faster recursion. But anyways, a BFS solution memorizing level:\n\n\n    public class TrieNode {\n        public TrieNode[] chi
Seems like everybody prefers the faster recursion. But anyways, a BFS solution memorizing level:\n\n```    \n    public class TrieNode {\n        public TrieNode[] children = new TrieNode[26];\n        public boolean isWord = false;\n    }\n    \n    public TrieNode root = new TrieNode();\n\n    /** Initialize your data structure here. */\n    public WordDictionary() {\n        \n    }\n    \n    /** Adds a word into the data structure. */\n    public void addWord(String word) {\n        TrieNode node = root;\n        for (char c : word.toCharArray()) {\n            if (node.children[c - \'a\'] == null) {\n                node.children[c - \'a\'] = new TrieNode();\n            }\n            node = node.children[c - \'a\'];\n        }\n        node.isWord = true;\n    }\n    \n    /** Returns if the word is in the data structure. A word could contain the dot character \'.\' to represent any one letter. */\n    public boolean search(String word) {\n        TrieNode node = root;\n        Queue<TrieNode> queue = new LinkedList<>();\n        queue.offer(node);\n        int level = 0;\n        while (!queue.isEmpty() && level <= word.length()) {\n            int size = queue.size();\n\n            for (int i = 0; i < size; i++) {\n                TrieNode current = queue.poll();\n                \n                if (level == word.length()) {\n                    if (current.isWord) {\n                        return true;\n                    } else {\n                        continue;\n                    }\n                }\n                \n                char c = word.charAt(level);\n                \n                if (c == \'.\') {\n                    for (TrieNode t : current.children) {\n                        if (t != null) {\n                            queue.offer(t);\n                        }\n                    }\n                } else if (current.children[c - \'a\'] != null) {\n                    queue.offer(current.children[c - \'a\']);\n                }\n            }\n            level++;\n        }\n        return false;\n    }\n```
['Breadth-First Search', 'Trie', 'Iterator', 'Java']