Share my solution


  • 0
    C
    class Solution {
    public:
        int maximalRectangle(vector<vector<char>>& matrix) {
            if(matrix.empty()) return 0;
            
            int row = matrix.size();
            int col = matrix[0].size();
            for(int i=1; i<row; ++i){
                for(int j=0; j<col; ++j){
                    if(matrix[i][j] > '0' && matrix[i-1][j] > '0') matrix[i][j] = matrix[i-1][j]+1;
                }
            }
            
            int res = 0;
            for(int i=0; i<row; ++i){
                for(int j=0; j<col; ++j){
                    if(matrix[i][j] > '0'){
                        int num = matrix[i][j]-'0';
                        int cnt = 1;
                        res = max(res, cnt*num);
                        for(int k=j+1; k<col&&matrix[i][k]>'0'; ++k){
                            num = min(num, matrix[i][k]-'0');
                            res = max(res, ++cnt*num);
                        }
                    }
                }
            }
            
            return res;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.