-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
41 lines (38 loc) · 1.12 KB
/
Copy pathSolution.java
File metadata and controls
41 lines (38 loc) · 1.12 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
31
32
33
34
35
36
37
38
39
40
41
import java.util.ArrayList;
import java.util.List;
class Solution
{
public List<List<Integer>> removeInterval(int[][] intervals, int[] toBeRemoved)
{
final List<List<Integer>> result = new ArrayList<>();
for (int i = 0; i < intervals.length; i++)
{
final int start = intervals[i][0];
final int end = intervals[i][1];
if (start >= toBeRemoved[0] && end <= toBeRemoved[1])
{
continue;
}
if (end <= toBeRemoved[0] || start >= toBeRemoved[1])
{
result.add(List.of(start, end));
continue;
}
if (start >= toBeRemoved[0])
{
result.add(List.of(toBeRemoved[1], end));
continue;
}
if (end <= toBeRemoved[1])
{
result.add(List.of(start, toBeRemoved[0]));
}
else
{
result.add(List.of(start, toBeRemoved[0]));
result.add(List.of(toBeRemoved[1], end));
}
}
return result;
}
}