diff --git a/problems/1035.不相交的线.md b/problems/1035.不相交的线.md index 6f2b6646..660b1e27 100644 --- a/problems/1035.不相交的线.md +++ b/problems/1035.不相交的线.md @@ -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: