@@ -0,0 +1,2322 @@
+/**%0A * Problem Link: https://leetcode.com/problems/add-and-search-word-data-structure-design/%0A */%0Apublic class WordDictionary %7B%0A    private Trie tree = new Trie();%0A    // Adds a word into the data structure.%0A    public void addWord(String word) %7B%0A        tree.addWord(word);%0A    %7D%0A%0A    // Returns if the word is in the data structure. A word could%0A    // contain the dot character '.' to represent any one letter.%0A    public boolean search(String word) %7B%0A        return tree.searchWord(word);%0A    %7D%0A%7D%0Aclass TrieNode %7B%0A    public char text;%0A    TrieNode%5B%5D child;%0A    public boolean isWord;%0A    %0A    public TrieNode(char c) %7B%0A        text = c;%0A        child = new TrieNode%5B26%5D;%0A        isWord = false;%0A    %7D%0A%7D%0A%0Aclass Trie %7B%0A    public TrieNode root;%0A    %0A    public Trie()%7B%0A        root = new TrieNode(' ');%0A    %7D%0A    %0A    public void addWord(String word) %7B%0A        TrieNode node = root;%0A        for(int i=0; i%3Cword.length(); i++)%7B%0A            int a = word.charAt(i) - 'a';%0A            if(node.child%5Ba%5D == null) %7B%0A                node.child%5Ba%5D = new TrieNode(word.charAt(i));%0A            %7D%0A            node = node.child%5Ba%5D;%0A        %7D%0A        node.isWord = true;%0A    %7D%0A    %0A    public boolean searchWord(String word) %7B%0A        TrieNode node = root;%0A        return searchWord(root, word);%0A    %7D%0A    %0A    private boolean searchWord(TrieNode node, String s) %7B%0A        if(node == null) return false;%0A        if(s.length() == 1) %7B%0A            if(s.charAt(0) == '.') %7B%0A                for(int i=0; i%3Cnode.child.length; i++) %7B%0A                    if(node.child%5Bi%5D != null && node.child%5Bi%5D.isWord) return true;%0A                %7D%0A                return false;%0A            %7D else %7B%0A                int c = s.charAt(0) - 'a';%0A                return node.child%5Bc%5D != null && node.child%5Bc%5D.isWord;%0A            %7D%0A        %7D%0A        char c = s.charAt(0);%0A        if(c != '.') %7B%0A            return searchWord(node.child%5Bc-'a'%5D, s.substring(1));%0A        %7D%0A        for(int i=0; i%3Cnode.child.length; i++) %7B%0A            if(node.child%5Bi%5D != null && searchWord(node.child%5Bi%5D, s.substring(1))) return true;%0A        %7D%0A        return false;%0A     %7D%0A%7D%0A%0A// Your WordDictionary object will be instantiated and called as such:%0A// WordDictionary wordDictionary = new WordDictionary();%0A// wordDictionary.addWord(%22word%22);%0A// wordDictionary.search(%22pattern%22);%0A

Create Add_and_Search_Word_Data_structure_design.java