publicbooleanstartsWith(String prefix) { TrieNodecur= root; char[] array = prefix.toCharArray(); for(inti=0; i < array.length; i ++) { charele= array[i]; if(!cur.children.containsKey(ele)) { returnfalse; } cur = cur.children.get(ele); } returntrue; } }
/** * Your Trie object will be instantiated and called as such: * Trie obj = new Trie(); * obj.insert(word); * boolean param_2 = obj.search(word); * boolean param_3 = obj.startsWith(prefix); */