Skip to content

Commit 89d1f41

Browse files
committed
Update largest-rectangle-in-histogram.py
1 parent 035f018 commit 89d1f41

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Python/largest-rectangle-in-histogram.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ class Solution:
1616
def largestRectangleArea(self, height):
1717
increasing, area, i = [], 0, 0
1818
while i <= len(height):
19-
if len(increasing) == 0 or (i < len(height) and height[i] > height[increasing[-1]]):
19+
if not increasing or (i < len(height) and height[i] > height[increasing[-1]]):
2020
increasing.append(i)
2121
i += 1
2222
else:
2323
last = increasing.pop()
24-
if len(increasing) == 0:
24+
if not increasing:
2525
area = max(area, height[last] * i)
2626
else:
2727
area = max(area, height[last] * (i - increasing[-1] - 1 ))
@@ -30,4 +30,4 @@ def largestRectangleArea(self, height):
3030
if __name__ == "__main__":
3131
print Solution().largestRectangleArea([2, 0, 2])
3232
print Solution().largestRectangleArea([2, 1, 5, 6, 2, 3])
33-
33+

0 commit comments

Comments
 (0)