We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 36fb537 commit c31404dCopy full SHA for c31404d
Two Pointers/Forwarding/intervalIntersection.java
@@ -0,0 +1,28 @@
1
+class Solution {
2
+ public int[][] intervalIntersection(int[][] A, int[][] B) {
3
+ if (A == null || A.length == 0 || B == null || B.length == 0) {
4
+ return new int[][]{};
5
+ }
6
+ int a = 0;
7
+ int b = 0;
8
+ List<int[]> res = new ArrayList<>();
9
+ int i=0;
10
+ while(a < A.length && b < B.length) {
11
+
12
+ int start = Math.max(A[a][0], B[b][0]);
13
+ int end = Math.min(A[a][1], B[b][1]);
14
+ if (end >= start) {
15
+ res.add(new int[]{start, end});
16
17
18
+ if (A[a][1] == end) {
19
+ a++;
20
21
22
+ if (B[b][1] == end) {
23
+ b++;
24
25
26
+ return res.toArray(new int[res.size()][2]);
27
28
+}
0 commit comments