:type intervals: List[Interval] :rtype: List[Interval]
(self, _sentences)
| 27 | |
| 28 | class Solution(object): |
| 29 | def merge(self, _sentences): |
| 30 | """ |
| 31 | :type intervals: List[Interval] |
| 32 | :rtype: List[Interval] |
| 33 | """ |
| 34 | _sentences = sorted(_sentences, key=lambda x: x.start) |
| 35 | |
| 36 | if not _sentences: |
| 37 | return [] |
| 38 | |
| 39 | result = [] |
| 40 | |
| 41 | head = _sentences[0].start |
| 42 | tail = _sentences[0].end |
| 43 | length = len(_sentences) |
| 44 | for x in range(1, length): |
| 45 | i = _sentences[x] |
| 46 | if tail >= i.start: |
| 47 | tail = max(tail, i.end) |
| 48 | else: |
| 49 | result.append([head, tail]) |
| 50 | head = i.start |
| 51 | tail = i.end |
| 52 | |
| 53 | result.append([head, tail]) |
| 54 | return result |
| 55 | |
| 56 | test = ( |
| 57 | [(1, 10), (32, 45)], |
nothing calls this directly
no outgoing calls
no test coverage detected