Write a function to find the longest common prefix string amongst an array of strings.
我的代码:
public String longestCommonPrefix(String[] strs) {
if(strs.length==0) return "";
if(strs.length==1) return strs[0];
String common = strs[0];
while (common.length()>0) {
T:for (int i = 1; i < strs.length; i++) {
if (!strs[i].startsWith(common)) {
common= common.substring(0,common.length()-1);
break T;
}else if(i==strs.length-1){
return common;
}
}
}
return common;
}