public class Solution {
/**
* @param A, B: Two string.
* @return: the length of the longest common substring.
*/
public int longestCommonSubstring(String A, String B) {
// write your code here
if(A.length()==0||B.length()==0){
return 0;
}
String shortString=A;
String longString=B;
if(A.length()>B.length()){
shortString=B;
longString=A;
}
for(int i=shortString.length();i>=0;i--){
for(int j=0;j+i<=shortString.length();j++){
String temp=shortString.substring(j, i+j);
if(longString.contains(temp)){
return temp.length();
}
}
}
return 0;
}
}