Skip to content

Commit 64c8612

Browse files
committed
modify code
1 parent 3d7dbf9 commit 64c8612

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/class044/Code02_TrieTree.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
public class Code02_TrieTree {
1717

18+
// 如果将来增加了数据量,就改大这个值
1819
public static int MAXN = 150001;
1920

2021
public static int[][] tree = new int[MAXN][26];
@@ -43,21 +44,6 @@ public static void insert(String word) {
4344
end[cur]++;
4445
}
4546

46-
public static void delete(String word) {
47-
if (search(word)) {
48-
int cur = 1;
49-
for (int i = 0, path; i < word.length(); i++) {
50-
path = word.charAt(i) - 'a';
51-
if (--pass[tree[cur][path]] == 0) {
52-
tree[cur][path] = 0;
53-
return;
54-
}
55-
cur = tree[cur][path];
56-
}
57-
end[cur]--;
58-
}
59-
}
60-
6147
public static boolean search(String word) {
6248
int cur = 1;
6349
for (int i = 0, path; i < word.length(); i++) {
@@ -82,6 +68,21 @@ public static int prefixNumber(String pre) {
8268
return pass[cur];
8369
}
8470

71+
public static void delete(String word) {
72+
if (search(word)) {
73+
int cur = 1;
74+
for (int i = 0, path; i < word.length(); i++) {
75+
path = word.charAt(i) - 'a';
76+
if (--pass[tree[cur][path]] == 0) {
77+
tree[cur][path] = 0;
78+
return;
79+
}
80+
cur = tree[cur][path];
81+
}
82+
end[cur]--;
83+
}
84+
}
85+
8586
public static void clear() {
8687
for (int i = 1; i <= cnt; i++) {
8788
Arrays.fill(tree[i], 0);

0 commit comments

Comments
 (0)