hope
\n# Code\n\nclass Solution {\n    public int maximalRectangle(char[][] matrix) {\n        if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {\n
\n# Code\n```\nclass Solution {\n    public int maximalRectangle(char[][] matrix) {\n        if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {\n            return 0;\n        }\n\n        int m = matrix.length;\n        int n = matrix[0].length;\n\n        int[] heights = new int[n];\n        int[] leftBoundaries = new int[n];\n        int[] rightBoundaries = new int[n];\n        Arrays.fill(rightBoundaries, n);\n\n        int maxRectangle = 0;\n\n        for (int i = 0; i < m; i++) {\n            int left = 0;\n            int right = n;\n\n            updateHeightsAndLeftBoundaries(matrix[i], heights, leftBoundaries, left);\n\n            updateRightBoundaries(matrix[i], rightBoundaries, right);\n\n            maxRectangle = calculateMaxRectangle(heights, leftBoundaries, rightBoundaries, maxRectangle);\n        }\n\n        return maxRectangle;\n    }\n\n    private void updateHeightsAndLeftBoundaries(char[] row, int[] heights, int[] leftBoundaries, int left) {\n        for (int j = 0; j < heights.length; j++) {\n            if (row[j] == \'1\') {\n                heights[j]++;\n                leftBoundaries[j] = Math.max(leftBoundaries[j], left);\n            } else {\n                heights[j] = 0;\n                leftBoundaries[j] = 0;\n                left = j + 1;\n            }\n        }\n    }\n\n    private void updateRightBoundaries(char[] row, int[] rightBoundaries, int right) {\n        for (int j = rightBoundaries.length - 1; j >= 0; j--) {\n            if (row[j] == \'1\') {\n                rightBoundaries[j] = Math.min(rightBoundaries[j], right);\n            } else {\n                rightBoundaries[j] = right;\n                right = j;\n            }\n        }\n    }\n\n    private int calculateMaxRectangle(int[] heights, int[] leftBoundaries, int[] rightBoundaries, int maxRectangle) {\n        for (int j = 0; j < heights.length; j++) {\n            int width = rightBoundaries[j] - leftBoundaries[j];\n            int area = heights[j] * width;\n            maxRectangle = Math.max(maxRectangle, area);\n        }\n        return maxRectangle;\n    }\n}\n```
['Java']