import java.util.*; //这什么垃圾编辑器?

public class Solution { /** * longest common substring * @param str1 string字符串 the string * @param str2 string字符串 the string * @return string字符串 */ public String LCS(String str1, String str2) { int[][] dp = new int[str1.length()+1][str2.length() + 1]; int maxLen = 0; int index = 0; for(int i = 0;i < str1.length();i ++){ for(int j = 0;j < str2.length();j++){ if(str1.charAt(i) == str2.charAt(j)){ dp[i+1][j+1] = dp[i][j]+1; if(dp[i+1][j+1] > maxLen){ maxLen = dp[i+1][j+1] ; index = i; }

           }else{
               dp[i+1][j+1]  = 0;
           }
       }
   }
   return str1.substring(index - maxLen+1,index +1);

} }