Skip to content

Latest commit

 

History

History
38 lines (30 loc) · 937 Bytes

35.md

File metadata and controls

38 lines (30 loc) · 937 Bytes
 static bool comp(int &a,int &b)
     {
         return a>b;
     }
    int largestSubmatrix(vector<vector<int>>& matrix) {

        int m=matrix.size(),n=matrix[0].size();

        vector<int> height(n,0);
        int ans=0;

        for(int i=0;i<m;++i)                //calculate height of each column
        {
            for(int j=0;j<n;++j)
            {
                if(matrix[i][j] == 0)
                    height[j] = 0;
                else
                    height[j] += 1;
            }
        

        //sort
        vector<int> order_height = height;
            sort(order_height.begin(), order_height.end());
        //sort(height.begin(),height.end());

        for(int j=0;j<n;++j)
            ans=max(ans, order_height[j]*(n-j));
        }

        return ans;
    }