如果不存在公共前缀,返回空字符串 ""。
示例 1:
输入:strs = ["flower","flow","flight"]
输出:"fl"
示例 2:
输入:strs = ["dog","racecar","car"]
输出:""
解释:输入不存在公共前缀。
function maxPrefix(strs){
var first = strs[0];
var max = "";
if(strs.length == 0){return console.log(max);}
for(var i = 1;i < strs.length;i ++){
max = "";
for(var j = 0;j < strs[i].length;j ++){
if(first[j] == strs[i][j]){
max = max + first[j];
}
else{
first = max;
break;
}
}
}
return console.log(first);
}