private static boolean has(TrieNode n, String prefix, boolean checkHasWord) {
        if (prefix == null) return false;
        char[] characters = prefix.toCharArray();
        for (char ch: characters) {
            if (!n.children.containsKey(ch)) return false;
            n = n.children.get(ch);
        }
        if (checkHasWord) {
            return n.isWord;
        } else {
            return true;
        }
    }