Skip to content

Instantly share code, notes, and snippets.

@CodHeK
Created June 11, 2020 08:14
Show Gist options
  • Save CodHeK/10cabab5380b1379069d7394eb3801fe to your computer and use it in GitHub Desktop.
Save CodHeK/10cabab5380b1379069d7394eb3801fe to your computer and use it in GitHub Desktop.
newNode() {
return {
isLeaf: false,
children: {}
}
}
add(word) {
if(!this.trie) this.trie = this.newNode();
let root = this.trie;
for(const letter of word) {
if(!(letter in root.children)) {
root.children[letter] = this.newNode();
}
root = root.children[letter];
}
root.isLeaf = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment