Exemple #1
0
  public boolean contains(String key) {
    //   ADD YOUR CODE BELOW HERE

    TrieNode prefixNode = getPrefixNode(key);
    return (prefixNode != null && prefixNode.getDepth() == key.length() && prefixNode.isEndOfKey());

    //   ADD YOUR CODE ABOVE HERE
  }
Exemple #2
0
 private void preOrderTraverse(TrieNode node, ArrayList<String> list) {
   if (node.isEndOfKey()) {
     list.add(node.toString());
   }
   for (int i = 0; i < TrieNode.NUMCHILDREN; i++) {
     if (node.getChild((char) i) != null) {
       preOrderTraverse(node.getChild((char) i), list);
     }
   }
 }