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

Method search

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

Source from the content-addressed store, hash-verified

31 }
32
33 public boolean search(String word) {
34 TrieNode node = this.root;
35 for (char c : word.toCharArray()) {
36 // For each character in the word, if it's not a child of
37 // the current node, the word doesn't exist in the Trie.
38 if (!node.children.containsKey(c)) {
39 return false;
40 }
41 node = node.children.get(c);
42 }
43 // Return whether the current node is marked as the end of the
44 // word.
45 return node.isWord;
46 }
47
48 public boolean hasPrefix(String prefix) {
49 TrieNode node = this.root;

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected