(String word)
| 69 | } |
| 70 | |
| 71 | public static void delete(String word) { |
| 72 | if (search(word) > 0) { |
| 73 | int cur = 1; |
| 74 | // 下面这一行代码,讲课的时候没加 |
| 75 | // 本题不会用到pass[1]的信息,所以加不加都可以,不过正确的写法是加上 |
| 76 | pass[cur]--; |
| 77 | for (int i = 0, path; i < word.length(); i++) { |
| 78 | path = word.charAt(i) - 'a'; |
| 79 | if (--pass[tree[cur][path]] == 0) { |
| 80 | tree[cur][path] = 0; |
| 81 | return; |
| 82 | } |
| 83 | cur = tree[cur][path]; |
| 84 | } |
| 85 | end[cur]--; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | public static void clear() { |
| 90 | for (int i = 1; i <= cnt; i++) { |