Sharing my straightforward C++ solution with O(n^2) time with explanation
int maximalRectangle(vector<vector<char> > &matrix) {\n        if(matrix.empty()){\n            return 0;\n        }\n        int maxRec = 0;\n        vector<in
    int maximalRectangle(vector<vector<char> > &matrix) {\n        if(matrix.empty()){\n            return 0;\n        }\n        int maxRec = 0;\n        vector<int> height(matrix[0].size(), 0);\n        for(int i = 0; i < matrix.size(); i++){\n            for(int j = 0; j < matrix[0].size(); j++){\n                if(matrix[i][j] == '0'){\n                    height[j] = 0;\n                }\n                else{\n                    height[j]++;\n                }\n            }\n            maxRec = max(maxRec, largestRectangleArea(height));\n        }\n        return maxRec;\n    }\n    \n    int largestRectangleArea(vector<int> &height) {\n        stack<int> s;\n        height.push_back(0);\n        int maxSize = 0;\n        for(int i = 0; i < height.size(); i++){\n            if(s.empty() || height[i] >= height[s.top()]){\n                s.push(i);\n            }\n            else{\n                int temp = height[s.top()];\n                s.pop();\n                maxSize = max(maxSize, temp * (s.empty() ? i : i - 1 - s.top()));\n                i--;\n            }\n        }\n        return maxSize;\n    }\n\nIn order to solve this problem, I use the solution from "Largest Rectangle in Histogram". \n\nNow I assume you already know how to solve "Largest Rectangle in Histogram".\n\nWe can regard a matrix as many histograms. For example, given a matrix below:\n\n1 0 1 0\n\n0 1 0 1\n\n0 1 1 0\n\n1 0 1 0\n\n1 0 1 1\n\nFrom top to bottom, we can find these histograms:\n\nNumber 1: 1 0 1 0\n\nNumber 2: 0 1 0 1\n\nNumber 3: 0 2 1 0\n\nNumber 4: 1 0 2 0\n\nNumber 5: 2 0 3 1\n\nPass all of these histograms to the function which can solve "Largest Rectangle in Histogram". And then find the maximum one. \n\nFinally, we get the answer.
['C++']