Created
January 21, 2019 17:04
-
-
Save arpi-r/6f78386db9d6ed1a3f10877dab23a172 to your computer and use it in GitHub Desktop.
codebuddy week10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
# @param A : list of list of integers | |
# @return an integer | |
def histarea(self,h): | |
s = list() | |
maxarea = 0 | |
i= 0 | |
area = 0 | |
while i < len(h): | |
if (not s) or (h[s[-1]] <= h[i]): | |
s.append(i) | |
i += 1 | |
else: | |
top = s.pop() | |
area = (h[top] * ((i - s[-1] - 1) if s else i)) | |
maxarea = max(maxarea, area) | |
while s: | |
top = s.pop() | |
area = (h[top] * ((i - s[-1] - 1) if s else i)) | |
maxarea = max(maxarea, area) | |
return maxarea | |
def maximalRectangle(self, A): | |
l = A[0] | |
area = self.histarea(l) | |
maxarea = area | |
for i in range(1,len(A)): | |
for j in range(len(A[i])): | |
if A[i][j] == 1: | |
l[j] = l[j] + 1 | |
else: | |
l[j] = 0 | |
area = self.histarea(l) | |
if area > maxarea: | |
maxarea = area | |
return maxarea |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment