Class Solution

java.lang.Object
g0001_0100.s0085_maximal_rectangle.Solution

public class Solution extends Object
85 - Maximal Rectangle.<p>Hard</p> <p>Given a <code>rows x cols</code> binary <code>matrix</code> filled with <code>0</code>&rsquo;s and <code>1</code>&rsquo;s, find the largest rectangle containing only <code>1</code>&rsquo;s and return <em>its area</em>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/09/14/maximal.jpg" alt="" /></p> <p><strong>Input:</strong> matrix = [[&ldquo;1&rdquo;,&ldquo;0&rdquo;,&ldquo;1&rdquo;,&ldquo;0&rdquo;,&ldquo;0&rdquo;],[&ldquo;1&rdquo;,&ldquo;0&rdquo;,&ldquo;1&rdquo;,&ldquo;1&rdquo;,&ldquo;1&rdquo;],[&ldquo;1&rdquo;,&ldquo;1&rdquo;,&ldquo;1&rdquo;,&ldquo;1&rdquo;,&ldquo;1&rdquo;],[&ldquo;1&rdquo;,&ldquo;0&rdquo;,&ldquo;0&rdquo;,&ldquo;1&rdquo;,&ldquo;0&rdquo;]]</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong> The maximal rectangle is shown in the above picture.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> matrix = []</p> <p><strong>Output:</strong> 0</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> matrix = [[&ldquo;0&rdquo;]]</p> <p><strong>Output:</strong> 0</p> <p><strong>Example 4:</strong></p> <p><strong>Input:</strong> matrix = [[&ldquo;1&rdquo;]]</p> <p><strong>Output:</strong> 1</p> <p><strong>Example 5:</strong></p> <p><strong>Input:</strong> matrix = [[&ldquo;0&rdquo;,&ldquo;0&rdquo;]]</p> <p><strong>Output:</strong> 0</p> <p><strong>Constraints:</strong></p> <ul> <li><code>rows == matrix.length</code></li> <li><code>cols == matrix[i].length</code></li> <li><code>0 <= row, cols <= 200</code></li> <li><code>matrix[i][j]</code> is <code>'0'</code> or <code>'1'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maximalRectangle

      public int maximalRectangle(char[][] matrix)