Merge pull request #200 from nmydt/patch-3

添加 1035.不相交的线 Java版本
This commit is contained in:
Carl Sun
2021-05-19 23:50:17 +08:00
committed by GitHub

View File

@ -73,7 +73,24 @@ public:
Java
```java
class Solution {
public int maxUncrossedLines(int[] A, int[] B) {
int [][] dp = new int[A.length+1][B.length+1];
for(int i=1;i<=A.length;i++) {
for(int j=1;j<=B.length;j++) {
if (A[i-1]==B[j-1]) {
dp[i][j]=dp[i-1][j-1]+1;
}
else {
dp[i][j]=Math.max(dp[i-1][j], dp[i][j-1]);
}
}
}
return dp[A.length][B.length];
}
}
```
Python