mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-24 00:57:05 +08:00
1035.不相交的线.md, 增加Golang实现
This commit is contained in:
@ -109,6 +109,41 @@ class Solution:
|
|||||||
return dp[-1][-1]
|
return dp[-1][-1]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Golang:
|
||||||
|
|
||||||
|
```go
|
||||||
|
|
||||||
|
func maxUncrossedLines(A []int, B []int) int {
|
||||||
|
m, n := len(A), len(B)
|
||||||
|
dp := make([][]int, m+1)
|
||||||
|
for i := range dp {
|
||||||
|
dp[i] = make([]int, n+1)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 1; i <= len(A); i++ {
|
||||||
|
for j := 1; j <= len(B); j++ {
|
||||||
|
if (A[i - 1] == B[j - 1]) {
|
||||||
|
dp[i][j] = dp[i - 1][j - 1] + 1;
|
||||||
|
} else {
|
||||||
|
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dp[m][n];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func max(a, b int) int {
|
||||||
|
if a > b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JavaScript:
|
JavaScript:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
Reference in New Issue
Block a user