```
class Solution(object):
def merge(self, intervals):
r = []
for i in sorted(intervals, key=lambda i: i.start):
if not r or i.start > r[-1].end:
r.append(i)
elif i.end > r[-1].end:
r[-1].end = i.end
return r
```