We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 51745e2 commit 2898c76Copy full SHA for 2898c76
solution/0700-0799/0718.Maximum Length of Repeated Subarray/Solution.java
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ public int findLength(int[] A, int[] B) {
3
+ int ans = 0;
4
+ int[][] dp = new int[A.length + 1][B.length + 1];
5
+ for (int i = 1;i <= A.length;i++) {
6
+ for (int j = 1;j <= B.length;j++) {
7
+ if (A[i - 1] == B[j - 1]) {
8
+ dp[i][j] = dp[i - 1][j - 1] + 1;
9
+ ans = Math.max(ans, dp[i][j]);
10
+ } else {
11
+ dp[i][j] = 0;
12
+ }
13
14
15
+ return ans;
16
17
+}
0 commit comments