From 609d5a3bf490cfa151b40e60cb62c8ff751bbe56 Mon Sep 17 00:00:00 2001 From: mzuenni Date: Tue, 8 Jul 2025 17:28:57 +0200 Subject: fix trie --- content/string/trie.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'content/string/trie.cpp') 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 trie = {node()}; int traverse(const vector& 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& word, int x) { int insert(const vector& word) { return traverse(word, 1); } - bool erase(const vector& word) { int id = traverse(word, 0); if (id < 0 || trie[id].ends <= 0) return false; -- cgit v1.2.3