MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / merge

Method merge

Array/MergeArray.py:29–54  ·  view source on GitHub ↗

:type intervals: List[Interval] :rtype: List[Interval]

(self, _sentences)

Source from the content-addressed store, hash-verified

27
28class 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
56test = (
57 [(1, 10), (32, 45)],

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected