You are viewing a single comment's thread. Return to all comments →
your count is getting reset 0 at every call, better to use count in countStringWithPrefix and pass count as argument.
void numberOfPartialSearch(struct trie *Troot, int *count){ if (Troot->isleaf) (*count)++; for(int i = 0; ichildren[i] != NULL) { numberOfPartialSearch(Troot->children[i], count); } } } int partialSearch(struct trie *Troot, string s) { struct trie * temp = Troot; int len = s.length(); for(int i = 0; ichildren[index(s[i])] == NULL) { return 0; } temp = temp->children[index(s[i])]; } int count = 0; numberOfPartialSearch(temp, &count); return count; }
But I am getting time out in some test cases.
Seems like cookies are disabled on this browser, please enable them to open this website
Contacts
You are viewing a single comment's thread. Return to all comments →
your count is getting reset 0 at every call, better to use count in countStringWithPrefix and pass count as argument.
void numberOfPartialSearch(struct trie *Troot, int *count){ if (Troot->isleaf) (*count)++; for(int i = 0; ichildren[i] != NULL) { numberOfPartialSearch(Troot->children[i], count); } } } int partialSearch(struct trie *Troot, string s) { struct trie * temp = Troot; int len = s.length(); for(int i = 0; ichildren[index(s[i])] == NULL) { return 0; } temp = temp->children[index(s[i])]; } int count = 0; numberOfPartialSearch(temp, &count); return count; }
But I am getting time out in some test cases.