Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
max area rectangle
histogram = [6, 2, 5, 4, 5, 1, 6] stack = list() max_area = 0 index = 0 area=0 while index < len(histogram): if (not stack) or (histogram[stack[-1]] <= histogram[index]): stack.append(index) index += 1 else: top_of_stack = stack.pop() area = (histogram[top_of_stack] * ((index - stack[-1] - 1) if stack else index)) max_area = max(max_area, area) print(stack,end=" ") print(index,end=" ") print(area) while stack: top_of_stack = stack.pop() area = (histogram[top_of_stack] * ((index - stack[-1] - 1) if stack else index)) max_area = max(max_area, area) print( max_area)
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
E
library
0
short hand if else
Set
Sum
PyTypeSub
snake water gun correct
Calender 2019
MBTI
Please log in to post a comment.