|
5 | 5 |
|
6 | 6 | publicclass_986 { |
7 | 7 | publicstaticclassSolution1 { |
8 | | -publicint[][]intervalIntersection(int[][]A,int[][]B) { |
| 8 | +publicint[][]intervalIntersection(int[][]firstList,int[][]secondList) { |
9 | 9 | inti =0; |
10 | 10 | intj =0; |
11 | 11 | List<int[]>list =newArrayList<>(); |
12 | | -while (i <A.length &&j <B.length) { |
13 | | -intstart =Math.max(A[i][0],B[j][0]); |
14 | | -intend =Math.min(A[i][1],B[j][1]); |
| 12 | +while (i <firstList.length &&j <secondList.length) { |
| 13 | +intstart =Math.max(firstList[i][0],secondList[j][0]); |
| 14 | +intend =Math.min(firstList[i][1],secondList[j][1]); |
15 | 15 | if (start <=end) { |
16 | 16 | list.add(newint[]{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 =newint[list.size()][2]; |
25 | | -for (intk =0;k <list.size();k++) { |
26 | | -result[k] =list.get(k); |
27 | | - } |
28 | | -returnresult; |
| 24 | +returnlist.toArray(newint[list.size()][2]); |
29 | 25 | } |
30 | 26 | } |
31 | 27 | } |