-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUncrossedLines.java
More file actions
40 lines (36 loc) · 1.21 KB
/
UncrossedLines.java
File metadata and controls
40 lines (36 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<<<<<<< HEAD
public class UncrossedLines{
public int maxUncrossedLines(int[] nums1, int[] nums2) {
int[] dp = new int[nums2.length+1];
for(int i = 1; i <= nums1.length; i++) {
int[] dpRow = new int[nums2.length+1];
for(int j = 1; j <= nums2.length; j++) {
if(nums1[i-1] == nums2[j-1]) {
dpRow[j] = dp[j-1] + 1;
} else {
dpRow[j] = Math.max(dp[j], dpRow[j-1]);
}
}
dp = dpRow;
}
return dp[nums2.length];
}
=======
public class UncrossedLines{
public int maxUncrossedLines(int[] nums1, int[] nums2) {
int[] dp = new int[nums2.length+1];
for(int i = 1; i <= nums1.length; i++) {
int[] dpRow = new int[nums2.length+1];
for(int j = 1; j <= nums2.length; j++) {
if(nums1[i-1] == nums2[j-1]) {
dpRow[j] = dp[j-1] + 1;
} else {
dpRow[j] = Math.max(dp[j], dpRow[j-1]);
}
}
dp = dpRow;
}
return dp[nums2.length];
}
>>>>>>> 622c86d59ac7148ac8e767904db50c6179b2fd40
}