【算法刷题】leetcode Maximal-Rectangle

Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.

 

思路参考  blog

 

    int maximalRectangle(vector > &matrix) {
        int res(0);
        int rows=matrix.size();
       
        if(rows == 0)
            return res;
        
        int cols = matrix[0].size();
        
        int** mat = new int* [rows];
        for(int i=0;i=0 && mat[m][j]>=mat[i][j];--m)
                    {
                        ++count;
                    }
                    for(int m=i+1;m=mat[i][j];++m)
                    {
                        ++count;
                    }
                    
                    count = count * mat[i][j];
                    res = max(res,count);
                }
            }
        }
        
        for(int k=0;k

 

你可能感兴趣的:(算法题)