Notion에서 작성한 글이라, 여기에서 더 깔끔하게 보실 수 있습니다! 😮😊
class Solution:
def maximalRectangle(self, matrix: List[List[str]]) -> int:
n, m = len(matrix), len(matrix[0])
dp = [[*map(int, r)]+[-1] for r in matrix]
for i in range(1, n):
for j in range(m):
if dp[i][j]: dp[i][j] += dp[i-1][j]
mx = 0
for row in dp:
stack = [-1]
for i in range(m+1):
while row[i] < row[stack[-1]]:
sq = row[stack.pop()] * (i-1-stack[-1])
if mx < sq: mx = sq
stack.append(i)
return mx
Memo