Description
Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.
Examples
Input:
matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]Output:
6Explanation:
The maximal rectangle is shown in the above picture.
Input:
matrix = [["0"]]Output:
0Explanation:
Edge case returning zero.
Input:
matrix = [["1","1","1"],["1","1","1"],["1","1","1"]]Output:
9Explanation:
The entire 3x3 matrix is filled with 1's, so the maximal rectangle is the entire matrix itself with area 3 × 3 = 9. This demonstrates the case where the optimal solution uses the complete matrix.
Constraints
- •
1 ≤ rows, cols ≤ 200 - •
matrix[i][j] is '0' or '1'