File tree 1 file changed +6
-10
lines changed
src/main/java/com/fishercoder/solutions 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change 5
5
6
6
public class _986 {
7
7
public static class Solution1 {
8
- public int [][] intervalIntersection (int [][] A , int [][] B ) {
8
+ public int [][] intervalIntersection (int [][] firstList , int [][] secondList ) {
9
9
int i = 0 ;
10
10
int j = 0 ;
11
11
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 ]);
15
15
if (start <= end ) {
16
16
list .add (new int []{start , end });
17
17
}
18
- if (end == A [i ][1 ]) {
18
+ if (end == firstList [i ][1 ]) {
19
19
i ++;
20
20
} else {
21
21
j ++;
22
22
}
23
23
}
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 ]);
29
25
}
30
26
}
31
27
}
You can’t perform that action at this time.
0 commit comments