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

Sign up
Appearance settings

Commit f928875

Browse files
Merge pull request #161 from QuinnDK/添加0718最长重复子数组Go版本
添加0718最长重复子数组Go版本
2 parents cd3a60a + e191a71 commit f928875

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

‎problems/0718.最长重复子数组.md‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,28 @@ Python:
160160
161161
162162
Go:
163-
163+
```Go
164+
func findLength(A []int, B []int) int {
165+
m, n := len(A), len(B)
166+
res := 0
167+
dp := make([][]int, m+1)
168+
for i := 0; i <= m; i++ {
169+
dp[i] = make([]int, n+1)
170+
}
171+
172+
for i := 1; i <= m; i++ {
173+
for j := 1; j <= n; j++ {
174+
if A[i-1] == B[j-1] {
175+
dp[i][j] = dp[i-1][j-1] + 1
176+
}
177+
if dp[i][j] > res {
178+
res = dp[i][j]
179+
}
180+
}
181+
}
182+
return res
183+
}
184+
```
164185

165186

166187

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /