diff --git a/problems/0718.最长重复子数组.md b/problems/0718.最长重复子数组.md index 204a513b..bef616d3 100644 --- a/problems/0718.最长重复子数组.md +++ b/problems/0718.最长重复子数组.md @@ -154,7 +154,25 @@ public: Java: - +```java +class Solution { + public int findLength(int[] nums1, int[] nums2) { + int result = 0; + int[][] dp = new int[nums1.length + 1][nums2.length + 1]; + + for (int i = 1; i < nums1.length + 1; i++) { + for (int j = 1; j < nums2.length + 1; j++) { + if (nums1[i - 1] == nums2[j - 1]) { + dp[i][j] = dp[i - 1][j - 1] + 1; + max = Math.max(max, dp[i][j]); + } + } + } + + return result; + } +} +``` Python: