mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
Update 0718.最长重复子数组.md
This commit is contained in:
@ -160,7 +160,28 @@ Python:
|
|||||||
|
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
```Go
|
||||||
|
func findLength(A []int, B []int) int {
|
||||||
|
m, n := len(A), len(B)
|
||||||
|
res := 0
|
||||||
|
dp := make([][]int, m+1)
|
||||||
|
for i := 0; i <= m; i++ {
|
||||||
|
dp[i] = make([]int, n+1)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 1; i <= m; i++ {
|
||||||
|
for j := 1; j <= n; j++ {
|
||||||
|
if A[i-1] == B[j-1] {
|
||||||
|
dp[i][j] = dp[i-1][j-1] + 1
|
||||||
|
}
|
||||||
|
if dp[i][j] > res {
|
||||||
|
res = dp[i][j]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user