We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 65d9577 commit 609d5a3Copy full SHA for 609d5a3
1 file changed
content/string/trie.cpp
@@ -10,13 +10,14 @@ vector<node> trie = {node()};
10
int traverse(const vector<int>& word, int x) {
11
int id = 0;
12
for (int c : word) {
13
- if (id < 0 || (trie[id].words == 0 && x <= 0)) return -1;
+ if (trie[id].words == 0 && x <= 0) return -1;
14
trie[id].words += x;
15
if (trie[id].nxt[c] < 0 && x > 0) {
16
trie[id].nxt[c] = sz(trie);
17
trie.emplace_back();
18
}
19
id = trie[id].nxt[c];
20
+ if (id < 0) return -1;
21
22
23
trie[id].ends += x;
@@ -26,7 +27,6 @@ int traverse(const vector<int>& word, int x) {
26
27
int insert(const vector<int>& word) {
28
return traverse(word, 1);
29
-
30
bool erase(const vector<int>& word) {
31
int id = traverse(word, 0);
32
if (id < 0 || trie[id].ends <= 0) return false;
0 commit comments