public TrieNode(char val) {
childNode = new TrieNode[26];
/** Initialize your data structure here. */
root = new TrieNode(' ');
/** Inserts a word into the trie. */
public void insert(String word) {
if (word == null || word.length() == 0) {
for (char c : word.toCharArray()) {
if (curNode.childNode[index] == null) {
curNode.childNode[index] = new TrieNode(c);
curNode = curNode.childNode[index];
/** Returns if the word is in the trie. */
public boolean search(String word) {
if (word == null || word.length() == 0) {
for (char c : word.toCharArray()) {
if (curNode.childNode[index] == null) {
curNode = curNode.childNode[index];
/** Returns if there is any word in the trie that starts with the given prefix. */
public boolean startsWith(String prefix) {
if (prefix == null || prefix.length() == 0) {
for (char c : prefix.toCharArray()) {
if (curNode.childNode[index] == null) {
curNode = curNode.childNode[index];
* Your Trie object will be instantiated and called as such:
* boolean param_2 = obj.search(word);
* boolean param_3 = obj.startsWith(prefix);