diff options
| author | Gloria Mundi <gloria@gloria-mundi.eu> | 2025-11-19 02:20:56 +0100 |
|---|---|---|
| committer | Gloria Mundi <gloria@gloria-mundi.eu> | 2025-11-19 02:20:56 +0100 |
| commit | 17232918b51d27500af905dc3d3d82cd43d6ddf5 (patch) | |
| tree | 1c5d52f03eead415cc53317008032fe84238c187 /content/string | |
| parent | bf4eda36d4c13be468236bf33baa2574e8692ca7 (diff) | |
| parent | cdeded176c18240579168ee8461c5101abb47e78 (diff) | |
merge mzuenni
Diffstat (limited to 'content/string')
| -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 db39c43..64d7beb 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] = ssize(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; |
