Complete the code to create a new Trie node.
func newNode() *TrieNode {
return &TrieNode{
children: make(map[rune]*TrieNode),
isEnd: [1],
}
}The new Trie node should start with isEnd set to false because it does not represent the end of a word yet.
Complete the code to check if a child node exists for a character.
if _, ok := current.children[[1]]; !ok { current.children[[1]] = newNode() }
We check if the child node for the current character exists using the variable representing the character, here named 'char'.
Fix the error in marking the end of a word in the insert function.
current.[1] = trueThe correct field to mark the end of a word in the Trie node is 'isEnd'.
Fill both blanks to complete the loop that inserts characters into the Trie.
for _, [1] := range [2] { if _, ok := current.children[char]; !ok { current.children[char] = newNode() } current = current.children[char] }
The loop iterates over each character 'char' in the string 'word' to insert it into the Trie.
Fill all three blanks to complete the insert function for the Trie.
func (t *Trie) Insert([1] string) { current := t.root for _, [2] := range [1] { if _, ok := current.children[[2]]; !ok { current.children[[2]] = newNode() } current = current.children[[2]] } current.isEnd = true }
The function takes 'word' as input, iterates over each character 'char' in 'word', and inserts nodes accordingly.