Advertisement
Guest User

Untitled

a guest
Nov 30th, 2021
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. public class Solution {
  2.     public int maximalRectangle(char[][] matrix) {
  3.  
  4.         int max = 0;
  5.         for (int i = 0; i < matrix.length; i++) {
  6.             for (int j = 0; j < matrix[0].length; j++) {
  7.                 int width = 0;
  8.                 int height = 0;
  9.  
  10.                 for (int k = i; k < matrix.length && matrix[k][j] == '1'; k++) {
  11.                     width++;
  12.                 }
  13.  
  14.                 for (int k = i; k < i + width; k++) {
  15.                     for (int l = j; l < matrix[0].length; l++) {
  16.                         if (matrix[k][l] == '0') {
  17.                             width = k - i;
  18.                             if (width * height > max) {
  19.                                 max = width * height;
  20.                             }
  21.                         }
  22.                     }
  23.                     height++;
  24.                 }
  25.  
  26.                 if (width * height > max) {
  27.                     max = width * height;
  28.                 }
  29.  
  30.             }
  31.         }
  32.         return max;
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement