Implement a trie with insert, search, and startsWith methods.

Example:

Trie trie = new Trie();

trie.insert("apple");
trie.search("apple");   // returns true
trie.search("app");     // returns false
trie.startsWith("app"); // returns true
trie.insert("app");   
trie.search("app");     // returns true
Note:

You may assume that all inputs are consist of lowercase letters a-z.
All inputs are guaranteed to be non-empty strings.

Solution:

type Trie struct {
    // val byte
    childs [26] *Trie
    count int
}


/** Initialize your data structure here. */
func Constructor() Trie {
    return Trie{}
}


/** Inserts a word into the trie. */
func (this *Trie) Insert(word string)  {
    node := this
    size := len(word)
    for i := 0; i < size; i++ {
        idx := word[i] - 'a'
        if node.childs[idx] == nil {
            node.childs[idx] = &Trie{}
        }
        node = node.childs[idx]
    }

    node.count++;
}


/** Returns if the word is in the trie. */
func (this *Trie) Search(word string) bool {
    node := this;
    size := len(word)
    for i := 0; i < size; i++ {
        idx := word[i] - 'a'
        if node.childs[idx] == nil {
            return false
        }
        node = node.childs[idx]
    }
    if node.count > 0 {
        return true;
    }
    return false
}


/** Returns if there is any word in the trie that starts with the given prefix. */
func (this *Trie) StartsWith(prefix string) bool {
    node := this;    
    size := len(prefix);

    for i:=0; i < size; i++ {
        idx := prefix[i] - 'a'
        if node.childs[idx] == nil {
            return false
        }
        node = node.childs[idx]

    }

    return true;
}


/**
 * Your Trie object will be instantiated and called as such:
 * obj := Constructor();
 * obj.Insert(word);
 * param_2 := obj.Search(word);
 * param_3 := obj.StartsWith(prefix);
 */