public boolean search(String word) {
            TrieNode ptr = root;
            for (char c : word.toCharArray()) {
                if (ptr.children[c - 'a'] == null) {
                    return false;
                }
                ptr = ptr.children[c - 'a'];
            }
            return ptr.end;
        }