# LeetCode—352. Data Stream as Disjoint Intervals

finish中get(val)不为null，则处理，为null则不处理

before和end同时不为null，取出前后Interval，list中删掉前Interval，后Interval的start=前Interval的start。删除end的数据，替换beofe的数据

before同为空，则单独新增

GitHub地址：https://github.com/corpsepiges/leetcode

<span style="font-size:14px;">/**
* Definition for an interval.
* public class Interval {
*     int start;
*     int end;
*     Interval() { start = 0; end = 0; }
*     Interval(int s, int e) { start = s; end = e; }
* }
*/
public class SummaryRanges {
Map<Integer, Interval> before ;
Map<Integer,Interval> end;
Map<Integer,Integer> finish;
List<Interval> list;
/** Initialize your data structure here. */
public SummaryRanges() {
before=new HashMap<Integer, Interval>();
end=new HashMap<Integer, Interval>();
finish=new HashMap<Integer,Integer>();
list=new ArrayList<>();
}

if (finish.get(val)==null) {
if (before.get(val)==null&&end.get(val)==null) {
Interval iv=new Interval(val,val);
before.put(val-1, iv);
end.put(val+1, iv);
if (list.size()==0) {
}else if (list.get(0).start>val) {
}else{
for (int i = list.size()-1; i>=0; i--) {
if (val>list.get(i).end) {
break;
}
}
}
}else if(before.get(val)==null){
end.get(val).end=val;
end.put(val+1, end.get(val));
end.remove(val);
}else if(end.get(val)==null){
before.get(val).start=val;
before.put(val-1, before.get(val));
before.remove(val);
}else{
Interval b=end.get(val);
Interval e=before.get(val);
e.start=b.start;
end.remove(val);
before.remove(val);
before.put(b.start-1, e);
list.remove(b);
}
finish.put(val, 1);
}
}

public List<Interval> getIntervals() {
return list;
}
}

/**
* Your SummaryRanges object will be instantiated and called as such:
* SummaryRanges obj = new SummaryRanges();
*/</span>