Skip to content

Commit 386dd0e

Browse files
authored
Create maximum-score-of-a-good-subarray.py
1 parent dba9768 commit 386dd0e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
class Solution(object):
5+
def largestRectangleArea(self, heights):
6+
"""
7+
:type heights: List[int]
8+
:rtype: int
9+
"""
10+
stk, result, i = [-1], 0, 0
11+
for i in xrange(len(heights)+1):
12+
while stk[-1] != -1 and (i == len(heights) or heights[stk[-1]] >= heights[i]):
13+
result = max(result, heights[stk.pop()]*((i-1)-stk[-1]))
14+
stk.append(i)
15+
return result

0 commit comments

Comments
 (0)