SHARE
TWEET

Leetcode

a guest Jan 20th, 2020 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2.     public int[][] intervalIntersection(int[][] A, int[][] B) {
  3.         ArrayList<int[]> res = new ArrayList<int[]>();
  4.         int i=0,j=0,k = 0;
  5.         while(i<A.length && j<B.length){
  6.             int x1 = A[i][0];
  7.             int y1 = A[i][1];
  8.             int x2 = B[j][0];
  9.             int y2 = B[j][1];
  10.            
  11.             int x = Math.max(x1,x2);
  12.             int y = Math.min(y1,y2);
  13.             if(x<=y){
  14.                 // op[k] = new int[] {x,y};
  15.                 // k++;
  16.                 res.add(new int[] {x,y});
  17.             }
  18.            
  19.             if(A[i][1]<B[j][1]){
  20.                 i++;
  21.             }else{
  22.                 j++;
  23.             }
  24.            
  25.         }
  26.        
  27.         int[][] op = new int[res.size()][2];
  28.         op = res.toArray(op);
  29.         return op;
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top