Merge pull request #161 from QuinnDK/添加0718最长重复子数组Go版本

添加0718最长重复子数组Go版本
This commit is contained in:
Carl Sun
2021-05-17 21:48:14 +08:00
committed by GitHub

View File

@ -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
}
```