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 }
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); } } }