class Solution {
    public int findLength(int[] A, int[] B) {
        return subLength(A,B,A.length-1,B.length-1);
    }
    private int subLength(int[] A, int[] B, int lenA, int lenB)
    {
        int temp1=0,temp2=0;
        if(lenA ==-1 || lenB==-1) return 0;
        if(A[lenA] == B[lenB])
        {
            return subLength(A,B,lenA-1,lenB-1)+1;
        }
        temp1 = subLength(A,B,lenA-1,lenB);
        temp2 = subLength(A,B,lenA,lenB-1);
        return (temp1>temp2)?temp1:temp2;
    }
}