题目:
题解:
type Trie struct {children [26]*TrieisEnd bool
}func Constructor() Trie {return Trie{}
}func (t *Trie) Insert(word string) {node := tfor _, ch := range word {ch -= 'a'if node.children[ch] == nil {node.children[ch] = &Trie{}}node = node.children[ch]}node.isEnd = true
}func (t *Trie) SearchPrefix(prefix string) *Trie {node := tfor _, ch := range prefix {ch -= 'a'if node.children[ch] == nil {return nil}node = node.children[ch]}return node
}func (t *Trie) Search(word string) bool {node := t.SearchPrefix(word)return node != nil && node.isEnd
}func (t *Trie) StartsWith(prefix string) bool {return t.SearchPrefix(prefix) != nil
}