Untitled
unknown
c_cpp
2 years ago
790 B
11
Indexable
class Solution{
public:
void helper(trie_node_t *root,int pos,char key[],int &n,bool &flag){
//base case
if(!root)return;
if(pos == n){
if(root->value){
root->value--;
flag=true;
}
}
helper(root->children[key[pos]-'a'],pos+1,key,n,flag);
if(flag)root->value--;
if(root->children[key[pos]-'a']->value==0){
trie_node *tmp = root->children[key[pos]-'a'];
root->children[key[pos]-'a'] = NULL;
delete(tmp);
}
}
void deleteKey(trie_node_t *root, char key[])
{
//Code here
// int c = sizeof(key)/sizeof(key[0]);
int c = strlen(key);
//cout<<" ys "<<c<<" size "<<endl;
bool flag = false;
helper(root,0,key,c,flag);
}
};Editor is loading...