public static int longestCommonSubstring(String A, String B) {
        // write your code here
        int m=A.length(), n=B.length();
        int[][] t=new int[m+1][n+1];
        int rel=0;
        for (int i=1;i<=m;++i)
            for (int j=1;j<=n;++j)
                if (A.charAt(i-1)==B.charAt(j-1))
                    rel=Math.max(t[i][j]=t[i-1][j-1]+1,rel);
        return rel;
    }