public class Solution {
/**
*
* @param strs string字符串一维数组
* @return string字符串
*/
public String longestCommonPrefix (String[] strs) {
// write code here
if(strs == null || strs.length == 0){
return "";
}
String first = strs[0];
if(strs.length == 1){
return first;
}
StringBuffer sb = new StringBuffer();;
for(int i = 0;i<first.length();i++){
char next = first.charAt(i);
boolean has = true;
for(int j = 0;j<strs.length;j++){
if(i >= strs[j].length() || strs[j].charAt(i) != next){
has = false;
}
}
if(has){
sb.append(next);
}
}
return sb.toString();
}
}