Maximum Length of Repeated Subarray LeetCode solution in Python

1
class Solution:
2
def findLength(self, nums1: List[int], nums2: List[int]) -> int:
3
dp = [[0] * (len(nums1) + 1) for _ in range(len(nums2) + 1)]
4
max_len = 0
5
for row in range(len(nums2)):
6
for col in range(len(nums1)):
7
if nums2[row] == nums1[col]:
8
dp[row][col] = 1 + dp[row - 1][col - 1]
9
max_len = max(max_len, dp[row][col])
10
else:
11
dp[row][col] = 0
12
return max_len

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0