mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
@ -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:
|
||||
|
||||
|
Reference in New Issue
Block a user