代码
public class Solution {
public string LongestCommonPrefix(string[] strs) {
string result="";
if(strs.Count()==0) return result;
for(int i=0;i<strs[0].Count();i++)
{
for(int j=0;j<strs.Count();j++)
{
if(i==strs[j].Count()||strs[j][i]!=strs[0][i])
return result;
}
result+=strs[0][i];
}
return result;
}
}
思路
字符串组中每个字符串中的第i个字符与第一个字符串中第i个字符比较
若有不等或字符串长度不够的情况 直接返回result字符串
否则将当前检测的字符加到result的尾部 i向后移动