From c1497b6e6eb4e2aa0c79b088d376561b04d628cf Mon Sep 17 00:00:00 2001 From: zhicheng lee <904688436@qq.com> Date: Mon, 19 Sep 2022 21:02:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=201035.=E4=B8=8D=E7=9B=B8?= =?UTF-8?q?=E4=BA=A4=E7=9A=84=E7=BA=BF.md=20=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原代码缩进、命名、空格不规范 --- problems/1035.不相交的线.md | 35 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/problems/1035.不相交的线.md b/problems/1035.不相交的线.md index 831b60c8..39124675 100644 --- a/problems/1035.不相交的线.md +++ b/problems/1035.不相交的线.md @@ -74,24 +74,27 @@ public: Java: - ```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]; - } + public int maxUncrossedLines(int[] nums1, int[] nums2) { + int len1 = nums1.length; + int len2 = nums2.length; + int[][] dp = new int[len1 + 1][len2 + 1]; + + for (int i = 1; i <= len1; i++) { + for (int j = 1; j <= len2; j++) { + if (nums1[i - 1] == nums2[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[len1][len2]; + } } - ``` +``` Python: ```python