标签:target code max com 区间 OLE 区间合并 list get
class Solution {
public int[][] insert(int[][] intervals, int[] newInterval) {
int len = intervals.length;
List<int[]> ans = new ArrayList<>(len);
boolean flag = false;
int L = newInterval[0], R = newInterval[1];
for(int[] interval : intervals) {
if(interval[0] > R){
if(!flag){
ans.add(new int[]{L, R});
flag = true;
}
ans.add(interval);
} else if(interval[1] < L){
ans.add(interval);
} else {
L = Math.min(L, interval[0]);
R = Math.max(R, interval[1]);
}
}
if(!flag) ans.add(new int[]{L, R});
return ans.toArray(new int[ans.size() - 1][]);
}
}
标签:target code max com 区间 OLE 区间合并 list get
原文地址:https://www.cnblogs.com/xiafrog/p/14543672.html