MCPcopy Create free account
hub / github.com/ByteByteGoHq/coding-interview-patterns / insert

Method insert

java/Tries/DesignATrie.java:20–31  ·  view source on GitHub ↗
(String word)

Source from the content-addressed store, hash-verified

18 }
19
20 public void insert(String word) {
21 TrieNode node = this.root;
22 for (char c : word.toCharArray()) {
23 // For each character in the word, if it's not a child of
24 // the current node, create a new TrieNode for that
25 // character.
26 node.children.putIfAbsent(c, new TrieNode());
27 node = node.children.get(c);
28 }
29 // Mark the last node as the end of a word.
30 node.isWord = true;
31 }
32
33 public boolean search(String word) {
34 TrieNode node = this.root;

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected