My O(n^3) solution for your reference
class Solution {\n    public:\n        int maximalRectangle(vector<vector<char> > &matrix) {\n            int num_i=matrix.size();\n            if (num_i==0) re
    class Solution {\n    public:\n        int maximalRectangle(vector<vector<char> > &matrix) {\n            int num_i=matrix.size();\n            if (num_i==0) return 0;\n            int num_j=matrix[0].size();\n            if (num_j==0) return 0;\n            vector<vector<int>> max_x(num_i,vector<int>(num_j,0));  //number of consecutive 1s to the left of matrix[i][j], including itself\n    \n            int area=0;\n            for (int i=0;i<num_i;i++){\n                for (int j=0;j<num_j;j++){\n                    if (matrix[i][j]=='1'){\n                        if (j==0) max_x[i][j]=1;\n                        else max_x[i][j]=max_x[i][j-1]+1;\n                        int y=1;\n                        int x=num_j;\n                        while((i-y+1>=0)&&(matrix[i-y+1][j]=='1')){\n                            x=min(x, max_x[i-y+1][j]);\n                            area=max(area,x*y);\n                            y++;\n                        } \n                    }\n                }\n            }\n            \n    \n            \n            return area;\n            \n            \n        }\n    };
[]