public List<Interval> mergeIntervals1(List<Interval> intervals){
        if(intervals.size() == 0 || intervals.size() == 1) return intervals;
        List<Interval> result = new ArrayList<Interval>();
        result.add(intervals.get(0));
        for(int i = 1; i < intervals.size(); i++){
            Interval curr = result.get(result.size() - 1);
            Interval next = intervals.get(i);
            if(curr.end < next.start){
                result.add(next);
            }else{
                Interval interval = new Interval();
                interval.start = curr.start;
                interval.end = curr.end <= next.end ? next.end : curr.end;
                result.remove(result.size() - 1);
                result.add(interval);
            }
        }
        return result;
    }