Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2f28a6f

Browse filesBrowse files
authored
Create 8_maxLengthRepeatedSubarray.py
1 parent 2a4a34e commit 2f28a6f
Copy full SHA for 2f28a6f

File tree

Expand file treeCollapse file tree

1 file changed

+13
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-0
lines changed
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def findLength(self, nums1: List[int], nums2: List[int]) -> int:
3+
m, n = len(nums1), len(nums2)
4+
dp = [[0] * (n+1) for _ in range(m+1)]
5+
ans = 0
6+
for i in range(1, m+1):
7+
for j in range(1, n+1):
8+
if nums1[i-1] == nums2[j-1]:
9+
dp[i][j] = dp[i-1][j-1] + 1
10+
else:
11+
dp[i][j] = 0
12+
ans = max(ans, dp[i][j])
13+
return ans

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.