from utils.interval import Interval

class Solution:
    def merge_intervals(self, intervals):
        """
        type: intervals: List[Interval]
        rtype: List[Interval]
        """
        result = []
        intervals.sort(key=lambda interval:interval.start)
        for interval in intervals:
            if not result or interval.start > result[-1].end:
                result.append(interval)
            else:
                result[-1].end = max(result[-1].end, interval.end)
        
        return result


interval1 = Interval(2, 5)
interval2 = Interval(7, 10)
interval3 = Interval(4, 6)
intervals = [interval1, interval3, interval2]
print(intervals)
solution = Solution()
print(solution.merge_intervals(intervals))