题解 | #最长公共子数组#

最长公共子数组

https://www.nowcoder.com/practice/6032826d387c4a10ad3690cce5fdb015


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;
    }
}




#算法题#
全部评论
同学,你求的是最长公共子序列还是最长公共子数组呀?
点赞 回复 分享
发布于 2022-12-19 23:15 北京

相关推荐

评论
5
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务