using System;
using System.Collections.Generic;
using System.Linq;
/*
public class Interval
{
	public int start;
	public int end;

	public Interval ()
	{
		start = 0;
		end = 0;
	}

	public Interval (int s, int e)
	{
		start = s;
		end = e;
	}
}
*/

class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param intervals Interval类一维数组 
     * @return Interval类一维数组
     */
    public List<Interval> merge (List<Interval> intervals) {
        intervals.Sort((x,y) => x.start.CompareTo(y.start));
		List<Interval> res = new List<Interval>();
		if(intervals.Count != 0) res.Add(intervals[0]);
		for(int i = 1; i < intervals.Count; i++){
			if(res[res.Count - 1].end < intervals[i].start){
				res.Add(intervals[i]);
			}
			else{
				res[res.Count - 1].end = Math.Max(res[res.Count - 1].end, intervals[i].end);

			}
		}
		return res;
    }
}