LeetCode OJ:Maximal Rectangle

2014-11-24 08:25:47 · 作者: · 浏览: 0

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.

算法思想:

最大子矩阵问题

class Solution {
public:
    int maximalRectangle(vector
  
    > &matrix) {
        if(matrix.empty())return 0;
        int len=matrix[0].size();
        vector
   
     H(len); vector
    
      L(len); vector
     
       R(len,len); int result=0; for(int i=0;i
      
       =0;j--){ if(matrix[i][j]=='1'){ R[j]=min(R[j],right); result=max(result,H[j]*(R[j]-L[j])); } else right=j; } } return result; } };