public int longestCommonSubstring(String A, String B) {
// write your code here
int count=0;
int max=0;
for(int i=0;i<A.length();i++)
for(int j=0;j<B.length();j++)
{
int linshi=i;//防止后面修改i使循环失效
if(A.charAt(linshi)==B.charAt(j))
{
while(j!=B.length()&&linshi!=A.length()&&A.charAt(linshi)==B.charAt(j))
{
count++;
linshi++;
j++;
}
max=count>max? count:max;
count=0;//别忘了要清零count
}
}
return max;
}
LintCode 最长公共子串
最新推荐文章于 2021-09-04 20:16:26 发布