public class Solution {
public String longestCommonPrefix(String[] strs) {
if (strs == null || strs.length == 0) {
return "";
}
int minLen = Integer.MAX_VALUE;
for (String str : strs) {
minLen = Math.min(str.length(), minLen);
}
if (minLen == 0) {
return "";
}
for (int i = 0; i < minLen; i++) {
char ch = strs[0].charAt(i);
for (String str : strs) {
if (str.charAt(i) != ch) {
return strs[0].substring(0, i);
}
}
}
return strs[0].substring(0, minLen);
}
}