718. Maximum Length of Repeated Subarray
标签(空格分隔): leetcode array medium
题目
Given two integer arrays A
and B
, return the maximum length of an subarray that appears in both arrays.
Example 1:
Input: A: [1,2,3,2,1] B: [3,2,1,4,7] Output: 3 Explanation:
Note:
- 1 <= len(A), len(B) <= 1000
- 0 <= A[i], B[i] < 100
思路
本题是个简单的动态规划问题,定义一个数组dp[j]来存储以A[i]为开头的最大子数组长。
代码