6
childs = new TrieNode[26];13
TrieNode root = new TrieNode();15
public String longestCommonPrefix(String[] strs) {16
if (strs.length == 0) return "";17
if (strs.length == 1) return strs[0];18
for (String str : strs) {19
insertIntoTrie(str.toLowerCase());21
return findCommonPrefix(strs[0], strs.length);24
private void insertIntoTrie(String str) {26
for (int i = 0; i < str.length(); i++) {27
if (ptr.childs[str.charAt(i) - 'a'] == null) {28
ptr.childs[str.charAt(i) - 'a'] = new TrieNode();30
ptr.childs[str.charAt(i) - 'a'].frequency++;32
ptr = ptr.childs[str.charAt(i) - 'a'];36
private String findCommonPrefix(String str, int n) {38
for (int i = 0; i < str.length(); i++) {39
if (root.childs[str.charAt(i) - 'a'].frequency != n) {43
root = root.childs[str.charAt(i) - 'a'];