Skip to content

Commit

Permalink
Merge pull request #10 from hsswiki/patch-1
Browse files Browse the repository at this point in the history
Resolve #9
  • Loading branch information
itcharge authored Jun 27, 2024
2 parents 0a05d2f + 6cb1cd6 commit 97feab7
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def search(self, word: str) -> bool:
return False # 直接返回 False
cur = cur.children[ch] # 令当前节点指向新建立的节点,然后继续查找下一个字符

return cur is not None and cur.isEnd # 判断当前节点是否为空,并且是否有单词结束标记
return cur.isEnd # 判断是否有单词结束标记
```

#### 2.3.2 字典树的查找前缀操作
Expand All @@ -140,7 +140,7 @@ def startsWith(self, prefix: str) -> bool:
if ch not in cur.children: # 如果当前节点的子节点中,不存在键为 ch 的节点
return False # 直接返回 False
cur = cur.children[ch] # 令当前节点指向新建立的节点,然后继续查找下一个字符
return cur is not None # 判断当前节点是否为空,不为空则查找成功
return True # 查找成功
```

## 3. 字典树的实现代码
Expand Down Expand Up @@ -175,7 +175,7 @@ class Trie: # 字典树
return False # 直接返回 False
cur = cur.children[ch] # 令当前节点指向新建立的节点,然后继续查找下一个字符

return cur is not None and cur.isEnd # 判断当前节点是否为空,并且是否有单词结束标记
return cur.isEnd # 判断是否有单词结束标记

# 查找字典树中是否存在一个前缀
def startsWith(self, prefix: str) -> bool:
Expand All @@ -184,7 +184,7 @@ class Trie: # 字典树
if ch not in cur.children: # 如果当前节点的子节点中,不存在键为 ch 的节点
return False # 直接返回 False
cur = cur.children[ch] # 令当前节点指向新建立的节点,然后继续查找下一个字符
return cur is not None # 判断当前节点是否为空,不为空则查找成功
return True # 查找成功
```

## 4. 字典树的算法分析
Expand Down

0 comments on commit 97feab7

Please sign in to comment.