解题过程就是寻找连续的最大值,每发现一次连续值就计算一次最大值! import java.util.*;

public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param A int整型一维数组 * @param B int整型一维数组 * @return int整型 */ public int longestCommonSubarry (int[] A, int[] B) { // write code here int lengthOfA = A.length; int lengthOfB = B.length; int max = 0; int[][] temp = new int[lengthOfA +1][lengthOfB +1]; for (int i = 1; i <= lengthOfA; i++) { for (int j = 1; j <= lengthOfB; j++) { if(A[i-1]==B[j-1]){ temp[i][j]=temp[i-1][j-1]+1;//连续值加1 max=Math.max(max,temp[i][j]);//计算最大值 } } } return max; } }