diff options
| author | mzuenni <michi.zuendorf@gmail.com> | 2025-07-08 17:28:57 +0200 |
|---|---|---|
| committer | mzuenni <michi.zuendorf@gmail.com> | 2025-07-08 17:29:21 +0200 |
| commit | 609d5a3bf490cfa151b40e60cb62c8ff751bbe56 (patch) | |
| tree | e707d791e0129565dda6fc9e39a39c1a240bb16f /content/string/trie.cpp | |
| parent | 65d957702f1e1d5fd202538fcf9ed6825eb45bb8 (diff) | |
fix trie
Diffstat (limited to 'content/string/trie.cpp')
| -rw-r--r-- | content/string/trie.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/content/string/trie.cpp b/content/string/trie.cpp index 03cf947..4e9f615 100644 --- a/content/string/trie.cpp +++ b/content/string/trie.cpp @@ -10,13 +10,14 @@ vector<node> trie = {node()}; int traverse(const vector<int>& word, int x) { int id = 0; for (int c : word) { - if (id < 0 || (trie[id].words == 0 && x <= 0)) return -1; + if (trie[id].words == 0 && x <= 0) return -1; trie[id].words += x; if (trie[id].nxt[c] < 0 && x > 0) { trie[id].nxt[c] = sz(trie); trie.emplace_back(); } id = trie[id].nxt[c]; + if (id < 0) return -1; } trie[id].words += x; trie[id].ends += x; @@ -26,7 +27,6 @@ int traverse(const vector<int>& word, int x) { int insert(const vector<int>& word) { return traverse(word, 1); } - bool erase(const vector<int>& word) { int id = traverse(word, 0); if (id < 0 || trie[id].ends <= 0) return false; |
