gpt-3.5-turbo-0125· OpenAI
WildChat-4.8M (AI2)
fix my code def maximalRectangle(self, matrix: List[List[str]]) -> int: if not matrix or…
- User
fix my code
def maximalRectangle(self, matrix: List[List[str]]) -> int: if not matrix or not matrix[0]: return 0 width, height = len(matrix[0]), len(matrix) h_histogram = [0] * (width + 1) max_area = 0 for i in range(height): for j in range(width): h_histogram[j] = h_histogram[j] + 1 if matrix[i][j] == '1' else 0 stack = [] for j in range(width + 1): while stack and (j == width or stack[-1] > h_histogram[j]): h = stack.pop() start = stack[-1] + 1 if stack else 0 max_area = max(max_area, h * (j - start)) stack.append(h_histogram[j]) return max_area - Assistant
The code has an indentation error in the function definition, and there is a syntax error when using the List type hint. Here is the corrected version:
from typing import List class Solution: def maximalRectangle(self, matrix: List[List[str]]) -> int: if not matrix or not matrix[0]: return 0 width, height = len(matrix[0]), len(matrix) h_histogram = [0] * (width + 1) max_area = 0 for i in range(height): for j in range(width): h_histogram[j] = h_histogram[j] + 1 if matrix[i][j] == '1' else 0 stack = [] for j in range(width + 1): while stack and (j == width or stack[-1] > h_histogram[j]): h = stack.pop() start = stack[-1] + 1 if stack else 0 max_area = max(max_area, h * (j - start)) stack.append(h_histogram[j]) return max_areaNow the indentation is fixed and the code is in runnable condition.