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 9e742d9 commit af05c08Copy full SHA for af05c08
merge-intervals/sora0319.java
@@ -0,0 +1,18 @@
1
+public class Solution {
2
+ public int[][] merge(int[][] intervals) {
3
+ List<int[]> output = new ArrayList<>();
4
+
5
+ Arrays.sort(intervals, (a, b) -> a[0]- b[0]);
6
7
+ for (int[] interval : intervals) {
8
+ if (output.isEmpty() || output.get(output.size() - 1)[1] < interval[0]) {
9
+ output.add(interval);
10
+ } else {
11
+ output.get(output.size() - 1)[1] = Math.max(output.get(output.size() - 1)[1], interval[1]);
12
+ }
13
14
15
+ return output.toArray(new int[output.size()][]);
16
17
+}
18
0 commit comments