Update 1035.不相交的线.md

This commit is contained in:
Baturu
2021-06-07 22:51:06 -07:00
committed by GitHub
parent a4b7399acb
commit d16cd90a6a

View File

@ -93,7 +93,18 @@ Java
``` ```
Python Python
```python
class Solution:
def maxUncrossedLines(self, A: List[int], B: List[int]) -> int:
dp = [[0] * (len(B)+1) for _ in range(len(A)+1)]
for i in range(1, len(A)+1):
for j in range(1, len(B)+1):
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[-1][-1]
```
Go Go