Designing A Trie Data Structure For Word Dictionary Operations
Implementing a Word Dictionary using Trie data structure. The `WordDictionary` class uses a Trie to store words and provides methods for adding words and searching for words with wildcards (`.`).
Problem
class WordDictionary {
Trie t;
public WordDictionary() {
t = new Trie();
}
public void addWord(String word) {
t.insert(word);
}
public boolean search(String word) {
return t.search(word);
}
}
class Node{
Node[] root = new Node[26];
boolean end = false;
public void add(char c, Node n){
root[c-'a'] = n;
}
public boolean present(char c){
return root[c-'a']!=null;
}
public Node get(char c){
return root[c-'a'];
}
public boolean isEnd(){
return end;
}
public void s...