Skip to content

Commit ac2783f

Browse files
authored
Create maximize-the-total-height-of-unique-towers.py
1 parent ef47dbc commit ac2783f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(nlogn)
2+
# Space: O(1)
3+
4+
# sort, greedy
5+
class Solution(object):
6+
def maximumTotalSum(self, maximumHeight):
7+
"""
8+
:type maximumHeight: List[int]
9+
:rtype: int
10+
"""
11+
maximumHeight.sort()
12+
result, prev = 0, maximumHeight[-1]+1
13+
for x in reversed(maximumHeight):
14+
prev = min(x, prev-1)
15+
if prev == 0:
16+
return -1
17+
result += prev
18+
return result

0 commit comments

Comments
 (0)