Skip to content

Commit 2905dec

Browse files
authored
Create describe-the-painting.py
1 parent c3e9fd5 commit 2905dec

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Python/describe-the-painting.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Time: O(nlogn)
2+
# Space: O(n)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def splitPainting(self, segments):
9+
"""
10+
:type segments: List[List[int]]
11+
:rtype: List[List[int]]
12+
"""
13+
counts = collections.defaultdict(int)
14+
for s, e, c in segments:
15+
counts[s] += c
16+
counts[e] -= c
17+
points = sorted(x for x in counts.iteritems())
18+
19+
result = []
20+
overlap = prev = 0
21+
for curr, cnt in points:
22+
if overlap:
23+
result.append([prev, curr, overlap])
24+
overlap += cnt
25+
prev = curr
26+
return result

0 commit comments

Comments
 (0)