class TrieNode {
    private char val;
    public Map<Character, TrieNode> dict;
    public boolean isLeaf;
    
    public TrieNode (char val) {
        this.val = val;
        this.dict = new HashMap<Character, TrieNode>();
        this.isLeaf = false;
    }
}

public class Trie {
    private TrieNode root;

    public Trie() {
        root = new TrieNode('\0');
    }

    // Inserts a word into the trie.
    public void insert(String word) {
        TrieNode curr = root;
        for (int i = 0; i < word.length(); i++) {
            char currChar = word.charAt(i);
            if (curr.dict.containsKey(currChar) == false) {
                TrieNode next = new TrieNode(currChar);
                curr.dict.put(currChar, next);
                curr = next;
            } else {
                TrieNode next = curr.dict.get(currChar);
                curr = next;
            }
            
            if (i == word.length() - 1) {
                curr.isLeaf = true;
            }
        }
    }

    // Returns if the word is in the trie.
    public boolean search(String word) {
        TrieNode curr = root;
        for (int i = 0; i < word.length(); i++) {
            char currChar = word.charAt(i);
            if (curr.dict.containsKey(currChar) == false) {
                return false;
            } else {
                curr = curr.dict.get(currChar);
            }
        }
        
        return curr.isLeaf;
    }

    // Returns if there is any word in the trie
    // that starts with the given prefix.
    public boolean startsWith(String prefix) {
        TrieNode curr = root;
        for (int i = 0; i < prefix.length(); i++) {
            char currChar = prefix.charAt(i);
            if (curr.dict.containsKey(currChar) == false) {
                return false;
            } else {
                curr = curr.dict.get(currChar);
            }
        }
        
        return true;
    }
}

// Your Trie object will be instantiated and called as such:
// Trie trie = new Trie();
// trie.insert("somestring");
// trie.search("key");

@@ -14,24 +14,16 @@
 e %7B%0A    
-private 
 char val
@@ -28,23 +28,16 @@
 al;%0A    
-public 
 Map%3CChar
@@ -59,31 +59,24 @@
 %3E dict;%0A    
-public 
 boolean isLe
@@ -92,23 +92,16 @@
     
-public 
 TrieNode
  (ch
@@ -100,18 +100,26 @@
 Node
- 
 (char v
-al
+, boolean b
 ) %7B%0A
@@ -138,18 +138,16 @@
 .val = v
-al
 ;%0A      
@@ -157,78 +157,55 @@
 his.
-dict = new HashMap%3CCharacter, TrieNode%3E();%0A        this.isLeaf = false
+isLeaf = b;%0A        this.dict = new HashMap%3C%3E()
 ;%0A  
@@ -211,23 +211,16 @@
    %7D%0A%7D%0A%0A
-public 
 class Tr
@@ -232,16 +232,8 @@
     
-private 
 Trie
@@ -244,16 +244,64 @@
  root;%0A%0A
+    /** Initialize your data structure here. */%0A
     publ
@@ -320,16 +320,21 @@
         
+this.
 root = n
@@ -349,16 +349,22 @@
 ode('%5C0'
+, true
 );%0A    %7D
@@ -364,23 +364,28 @@
 ;%0A    %7D%0A
+    
 %0A    /
-/
+**
  Inserts
@@ -398,32 +398,35 @@
 d into the trie.
+ */
 %0A    public void
@@ -580,32 +580,33 @@
             if (
+!
 curr.dict.contai
@@ -616,33 +616,24 @@
 ey(currChar)
- == false
 ) %7B%0A        
@@ -644,257 +644,134 @@
     
-TrieNode next = new TrieNode(currChar);%0A                curr.dict.put(currChar, next);%0A                curr = next;%0A            %7D else %7B%0A                TrieNode next = curr.dict.get(currChar);%0A                curr = next;%0A            %7D%0A            
+curr.dict.put(currChar, new TrieNode(currChar, false));%0A            %7D%0A            %0A            curr = curr.dict.get(currChar);
 %0A   
@@ -871,31 +871,36 @@
     %7D%0A    %7D%0A
+    
 %0A    /
-/
+**
  Returns if 
@@ -923,16 +923,19 @@
 he trie.
+ */
 %0A    pub
@@ -1100,32 +1100,33 @@
             if (
+!
 curr.dict.contai
@@ -1136,33 +1136,24 @@
 ey(currChar)
- == false
 ) %7B%0A        
@@ -1183,36 +1183,38 @@
            %7D
- else %7B%0A
+%0A        
     
+%0A
             
@@ -1241,38 +1241,24 @@
 (currChar);%0A
-            %7D%0A
         %7D%0A  
@@ -1298,23 +1298,28 @@
 ;%0A    %7D%0A
+    
 %0A    /
-/
+**
  Returns
@@ -1355,15 +1355,8 @@
 trie
-%0A    //
  tha
@@ -1386,16 +1386,19 @@
  prefix.
+ */
 %0A    pub
@@ -1581,16 +1581,17 @@
     if (
+!
 curr.dic
@@ -1617,17 +1617,8 @@
 har)
- == false
 ) %7B%0A
@@ -1664,20 +1664,22 @@
    %7D
- else %7B%0A
+%0A        
     
+%0A
     
@@ -1718,30 +1718,16 @@
 rChar);%0A
-            %7D%0A
         
@@ -1768,17 +1768,21 @@
   %7D%0A%7D%0A%0A/
-/
+**%0A *
  Your Tr
@@ -1836,20 +1836,19 @@
 ch:%0A
-//
+ *
  Trie 
-trie
+obj
  = n
@@ -1862,23 +1862,22 @@
 ();%0A
-// trie
+ * obj
 .insert(
 %22som
@@ -1876,42 +1876,99 @@
 ert(
-%22somestring%22);%0A// trie.search(%22key%22);
+word);%0A * boolean param_2 = obj.search(word);%0A * boolean param_3 = obj.startsWith(prefix);%0A */
 %0A

Update ImplementTrie.java