Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class MyClass {
- public static int end(int[] in) {
- return in[1];
- }
- public static int start(int[] in) {
- return in[0];
- }
- public static void main(String args[]) {
- List<int[]> A = Arrays.asList(new int[]{0, 2}, new int[]{5, 10}, new int[]{16, 20});
- List<int[]> B = Arrays.asList(new int[]{1, 5}, new int[]{10, 18}, new int[]{20, 23});
- List<int[]> res = new ArrayList<int[]>();
- int a=0, b=0;
- while( a < A.size() && b < B.size() && ( end(A.get(a)) <= end(B.get(b)) || end(B.get(b)) <= end(A.get(a)))) {
- int x = Math.max(start(A.get(a)), start(B.get(b)));
- int y = Math.min(end(A.get(a)), end(B.get(b)));
- int[] temp = new int[]{0, 0};
- temp[0] = x;
- temp[1] = y;
- res.add(temp);
- if( end(A.get(a)) < end(B.get(b))) {
- a++;
- } else {
- b++;
- }
- }
- for(int[] i : res) {
- System.out.print(i[0] + ",");
- System.out.print(i[1] + ",");
- System.out.println(" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement