public static int LCS(char query[], char text[]) { int len_query = query.length; int len_text= text.length; //数组c记录匹配情况,模拟二维矩阵 int[] c = new int[len_text]; int len, i, j; len=0; for(i=0; i=0; j--) { if(query[i] == text[j]) { if(i==0 || j==0) c[j]=1; else c[j]=c[j-1]+1; } else c[j] = 0; if(c[j] > len) len=c[j]; } System.out.println(Arrays.toString(c)); } return len; }
https://my.oschina.net/gaosheng/blog/308853
LCS(new char[]{'a','b','c','d'},new char[]{'b','c','d'});
[0, 0, 0]
[1, 0, 0][0, 2, 0][0, 0, 3]