# Definition for an interval. # class Interval: # def __init__(self, s=0, e=0): # self.start = s # self.end = e class Solution: # @param intervals, a list of Interval # @return a list of Interval def merge(self, intervals): intervals=sorted(intervals,key=lambda x:x.start) n=len(intervals) if not n: return [] rst=[intervals[0]] i=0 for i in range(1,n): if rst[-1].end<intervals[i].start: rst.append(intervals[i]) else: temp=Interval(rst[-1].start,max(rst[-1].end,intervals[i].end)) rst.pop() rst.append(temp) return rst
Thursday, September 18, 2014
Leetcode: Merge Intervals @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment