Skip to content

Commit 2898c76

Browse files
committed
add 0718 Solution for Java
1 parent 51745e2 commit 2898c76

File tree

1 file changed

+17
-0
lines changed
  • solution/0700-0799/0718.Maximum Length of Repeated Subarray

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)