Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c1497b6

Browse files
更新 1035.不相交的线.md 代码
原代码缩进、命名、空格不规范
1 parent 444064e commit c1497b6

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

‎problems/1035.不相交的线.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,27 @@ public:
7474
7575
7676
Java:
77-
```java
77+
```java
7878
class Solution {
79-
public int maxUncrossedLines(int[] A, int[] B) {
80-
int [][] dp = new int[A.length+1][B.length+1];
81-
for(int i=1;i<=A.length;i++) {
82-
for(int j=1;j<=B.length;j++) {
83-
if (A[i-1]==B[j-1]) {
84-
dp[i][j]=dp[i-1][j-1]+1;
85-
}
86-
else {
87-
dp[i][j]=Math.max(dp[i-1][j], dp[i][j-1]);
88-
}
89-
}
90-
}
91-
return dp[A.length][B.length];
92-
}
79+
public int maxUncrossedLines(int[] nums1, int[] nums2) {
80+
int len1 = nums1.length;
81+
int len2 = nums2.length;
82+
int[][] dp = new int[len1 + 1][len2 + 1];
83+
84+
for (int i = 1; i <= len1; i++) {
85+
for (int j = 1; j <= len2; j++) {
86+
if (nums1[i - 1] == nums2[j - 1]) {
87+
dp[i][j] = dp[i - 1][j - 1] + 1;
88+
} else {
89+
dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
90+
}
91+
}
92+
}
93+
94+
return dp[len1][len2];
95+
}
9396
}
94-
```
97+
```
9598

9699
Python:
97100
```python

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /