LeetCode986

    技术2022-08-01  68

    class Solution { public int[][] intervalIntersection(int[][] A, int[][] B) { List<int[]> ans = new ArrayList<>(); int i = 0; int j = 0; while(i < A.length && j < B.length){ int l = Math.max(A[i][0],B[j][0]); int r = Math.min(A[i][1],B[j][1]); if( l <= r){ ans.add(new int[]{l,r}); } if(A[i][1]<B[j][1]){ i++; } else{ j++; } } return ans.toArray(new int[ans.size()][]); } }

     

    Processed: 0.009, SQL: 9