我的LeetCode代码仓:https://github.com/617076674/LeetCode
原题链接:https://leetcode-cn.com/problems/add-and-search-word-data-structure-design/description/
题目描述:
知识点:Trie
思路:Trie存储单词
关于Trie的实现,可以参见LeetCode208——实现 Trie (前缀树)。
addWord和search的时间复杂度均是O(n),其中n为待添加单词的长度。
JAVA代码:
class WordDictionary {
private class Node {
private boolean isWord;
private HashMap<Character, Node> next;
public Node() {
isWord = false;
next = new HashMap