public static String longestCommonPrefix(String[] strs) {
        String prefix = "";
        if (strs == null || strs.length == 0) {
            return prefix;
        }
        if (strs.length == 1) {
            return strs[0];
        }

        int i, k = 0;
        while (true) {
            char p = ' ';
            for (i = 0; i < strs.length; i++) {
                if (k == strs[i].length()) {
                    break;
                }
                if (i == 0) {
                    p = strs[i].charAt(k);
                }
                if (p != strs[i].charAt(k)) {
                    break;
                }
            }
            if (i != strs.length) {
                break;
            }
            prefix += p;
            k++;
        }
        return prefix;
    }