-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution986.java
More file actions
30 lines (25 loc) · 1 KB
/
Copy pathSolution986.java
File metadata and controls
30 lines (25 loc) · 1 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
package Solutions;
import java.util.Arrays;
import Execute.Interval;
public class Solution986 {
public Interval[] intervalIntersection(Interval[] A, Interval[] B) {
Interval aws[] = new Interval[A.length * B.length];
int index = 0;
for(int i = 0 ; i < A.length ; i++){
for(int j = 0 ; j < B.length ; j++){
if(B[j].start > A[i].end || A[i].start > B[j].end ){
continue;
}else{
aws[index]=new Interval(Math.max(A[i].start,B[j].start), Math.min(A[i].end, B[j].end));
index++;
}
}
}
Interval returnAws[] = Arrays.copyOf(aws, index);
return returnAws;
}
}
// intialize constructor's array
//https://stackoverflow.com/questions/10456681/how-to-initialize-array-in-java-when-the-class-constructor-has-parameters
//algorithms
//https://scicomp.stackexchange.com/questions/26258/the-easiest-way-to-find-intersection-of-two-intervals