public static String longestCommonPrefix(String[] strs) {//accepted
        if (strs == null) return null;
        if (strs.length == 0) return "";
        char prefix[] = strs[0].toCharArray();
        int len = strs[0].length();
        for (int i = 1; i < strs.length; ++i) {
            len = Math.min(len,  strs[i].length());
            for (int j = 0; j < len; ++j) {
                if (strs[i].charAt(j) != prefix[j]) {
                    if (j < len) {
                        len = j;
                    }
                    break;
                }
            }
        }
        return new String(prefix, 0, len);
    }