public class Solution {
/**
*
* @param strs string字符串一维数组
* @return string字符串
*/
public static String longestCommonPrefix (String[] strs) {
int lens=strs.length;
if(lens==1){
return strs[0];
}
int times=Integer.MAX_VALUE;
String res=new String();
for(int index=0;index<lens;index++){
times=Math.min(times, strs[index].length());
}
for(int index=0;index<times;index++){
if(sign(index, strs)){
res=res+strs[0].charAt(index);
}else{
break;
}
}
return res;
}
public static boolean sign(int index,String[] strs){
int times=0;
for(int i=0;i<strs.length-1;i++){
if(strs[i].charAt(index)==strs[i+1].charAt(index)){
times++;
}else{
break;
}
}
if(times==strs.length-1){
return true;
}
return false;
}
}