1035. 不相交的线
class Solution:
def maxUncrossedLines(self, nums1: List[int], nums2: List[int]) -> int:
len1,len2 = len(nums1),len(nums2)
#转化为最长公共子序列问题
dp = [[0]*(len2+1) for _ in range(len1+1)]
res = 0
for i in range(1,len1+1):
for j in range(1,len2+1):
if nums1[i-1] == nums2[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[len1][len2]