Skip to content

Commit 06e8e30

Browse files
refactor 986
1 parent cb09450 commit 06e8e30

File tree

1 file changed

+6
-10
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+6
-10
lines changed

src/main/java/com/fishercoder/solutions/_986.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,23 @@
55

66
public class _986 {
77
public static class Solution1 {
8-
public int[][] intervalIntersection(int[][] A, int[][] B) {
8+
public int[][] intervalIntersection(int[][] firstList, int[][] secondList) {
99
int i = 0;
1010
int j = 0;
1111
List<int[]> list = new ArrayList<>();
12-
while (i < A.length && j < B.length) {
13-
int start = Math.max(A[i][0], B[j][0]);
14-
int end = Math.min(A[i][1], B[j][1]);
12+
while (i < firstList.length && j < secondList.length) {
13+
int start = Math.max(firstList[i][0], secondList[j][0]);
14+
int end = Math.min(firstList[i][1], secondList[j][1]);
1515
if (start <= end) {
1616
list.add(new int[]{start, end});
1717
}
18-
if (end == A[i][1]) {
18+
if (end == firstList[i][1]) {
1919
i++;
2020
} else {
2121
j++;
2222
}
2323
}
24-
int[][] result = new int[list.size()][2];
25-
for (int k = 0; k < list.size(); k++) {
26-
result[k] = list.get(k);
27-
}
28-
return result;
24+
return list.toArray(new int[list.size()][2]);
2925
}
3026
}
3127
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy