public int maximalRectangle(char[][] matrix) {
        int rows = matrix.length;
        if (rows == 0) {
            return 0;
        }
        int cols = matrix[0].length;
        //create histogram matrix
        int[][] histogram = new int[rows][cols];
        
        int max = 0;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                if (matrix[i][j] == '1') {
                    if (j == 0) {
                        histogram[i][j] = 1;
                    } else {
                        histogram[i][j] = histogram[i][j - 1] + 1;
                    }
                }
            }
        }
        //calculate
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                if (histogram[i][j] != 0) {
                    int minI = i;
                    int minRowWidth = histogram[i][j];
                    while (minI >= 0) {
                        minRowWidth = Math.min(minRowWidth, histogram[minI][j]);
                        int area = minRowWidth * (i - minI + 1);
                        max = Math.max(max, area);
                        minI--;
                    }
                }
            }
        }
        return max;
    }