Skip to content

Commit

Permalink
fixed trie
Browse files Browse the repository at this point in the history
  • Loading branch information
userr2232 committed Oct 14, 2021
1 parent f65aa68 commit 5836588
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Study/trie.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ void add_string(string s) {
for(int i = 0; i < n; ++i) {
string_counter[node]++;
int ord = s[i] - 'a';
int next_node = trie[node][ord];
if(next_node == 0) trie[node][ord] = ++nodeCounter, ends_here[next_node = nodeCounter] = true;
else if(i == n-1) ends_here[node] = true;
int& next_node = trie[node][ord];
if(next_node == 0) next_node = ++nodeCounter;
if(i == n-1) ends_here[node] = true;
node = next_node;
}
string_counter[node]++;
Expand Down

0 comments on commit 5836588

Please sign in to comment.