Skip to content

Commit 2a730e0

Browse files
committed
modify code
1 parent ddce646 commit 2a730e0

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed
Binary file not shown.

src/class044/Code01_TrieTree.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public void insert(String word) {
4242
node.end++;
4343
}
4444

45+
// 如果之前word插入过前缀树,那么此时删掉一次
46+
// 如果之前word没有插入过前缀树,那么什么也不做
4547
public void erase(String word) {
4648
if (countWordsEqualTo(word) > 0) {
4749
TrieNode node = root;
@@ -58,6 +60,7 @@ public void erase(String word) {
5860
}
5961
}
6062

63+
// 查询前缀树里,word单词出现了几次
6164
public int countWordsEqualTo(String word) {
6265
TrieNode node = root;
6366
for (int i = 0, path; i < word.length(); i++) {
@@ -70,6 +73,7 @@ public int countWordsEqualTo(String word) {
7073
return node.end;
7174
}
7275

76+
// 查询前缀树里,有多少单词以pre做前缀
7377
public int countWordsStartingWith(String pre) {
7478
TrieNode node = root;
7579
for (int i = 0, path; i < pre.length(); i++) {

0 commit comments

Comments
 (0)