classSolution{publicintfindLength(int[] nums1,int[] nums2){int n = nums1.length, m = nums2.length;int ret =0;for(int i =0; i < n; i++){int len = Math.min(m, n - i);int maxlen =maxLength(nums1, nums2, i,0, len);
ret = Math.max(ret, maxlen);}for(int i =0; i < m; i++){int len = Math.min(n, m - i);int maxlen =maxLength(nums1, nums2,0, i, len);
ret = Math.max(ret, maxlen);}return ret;}publicintmaxLength(int A[],int[] B,int addA,int addB,int len){int ret =0, k =0;for(int i =0; i < len; i++){if(A[addA + i]== B[addB + i]){
k++;}else{
ret = Math.max(ret, k);
k =0;}}// 防止A和B对比的值都是相等没有进入else中,那样的话ret就为0了。
ret = Math.max(ret, k);return ret;}}
题目题源代码class Solution { public int findLength(int[] nums1, int[] nums2) { int n = nums1.length, m = nums2.length; int ret = 0; for (int i = 0; i < n; i++) { int len = Math.min(m, n - i); int maxlen