public static int maximalRectangle(char[][] matrix) {

    if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
      return 0;
    }

    int[] curtLine = new int[matrix[0].length];
    for (int i = 0 ; i < curtLine.length ; i++) {
      curtLine[i] = matrix[0][i] - '0';
    }

    int max = largestRectangleArea(curtLine);

    for (int i = 1 ; i < matrix.length ; i++) {
      for (int j = 0 ; j < curtLine.length ; j++) {
        curtLine[j] = matrix[i][j] == '0' ? 0 : curtLine[j] + matrix[i][j] - '0';
      }
      max = Math.max(max, largestRectangleArea(curtLine));
    }

    return max;
  }