Maximal Rectangle [LeetCode]
Problem Description: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.
Basic idea: To increas one dimension by one, then calculate the maximum of other dimension every time.
 class Solution {
 public:
     int maximalRectangle(vector<vector<char> > &matrix) {
         // Note: The Solution object is instantiated only once and is reused by each test case.
         if(matrix.size() ==  || matrix[].size() == )
             return ;
         int max_area = ;
         int row = matrix.size();
         int column = matrix[].size();
         for(int i = ; i < row; i ++) {
             for( int j = ; j < column; j ++) {
                 if (matrix[i][j] == '')
                     continue;
                 int tmp_area = ;
                 int max_row_idx = row - ;
                 int max_column_idx = j;
                 while(max_column_idx < column){
                     int l;
                     for(l = i + ; l <= max_row_idx; l ++){
                          if (matrix[l][max_column_idx] == '')
                             break;
                     }
                     max_row_idx = l - ;
                     tmp_area = (max_row_idx - i + ) * (max_column_idx - j + );
                     if(tmp_area > max_area)
                         max_area = tmp_area;
                     //increase column
                     if ( matrix[i][max_column_idx + ] == ''){
                         max_column_idx ++;
                     }else{
                         break;
                     }
                 }
             }
         }
         return max_area;
     }
 };
Maximal Rectangle [LeetCode]的更多相关文章
- Maximal Rectangle [leetcode] 的三种思路
		第一种方法是利用DP.时间复杂度是 O(m * m * n) dp(i,j):矩阵中同一行以(i,j)结尾的所有为1的最长子串长度 代码例如以下: int maximalRectangle(vecto ... 
- Maximal Rectangle leetcode java
		题目: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones ... 
- 求解最大矩形面积 — leetcode 85. Maximal Rectangle
		之前切了道求解最大正方形的题,题解猛戳 这里.这道题 Maximal Rectangle 题意与之类似,但是解法完全不一样. 先来看这道题 Largest Rectangle in Histogram ... 
- leetcode Maximal Rectangle 单调栈
		作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4052721.html 题目链接:leetcode Maximal Rectangle 单调栈 ... 
- leetcode面试准备: Maximal Rectangle
		leetcode面试准备: Maximal Rectangle 1 题目 Given a 2D binary matrix filled with 0's and 1's, find the larg ... 
- LeetCode: Maximal Rectangle 解题报告
		Maximal RectangleGiven a 2D binary matrix filled with 0's and 1's, find the largest rectangle contai ... 
- [LeetCode] Largest Rectangle in Histogram O(n) 解法详析, Maximal Rectangle
		Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height ... 
- 【leetcode】Maximal Rectangle
		Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle conta ... 
- LeetCode之“动态规划”:Maximal Square && Largest Rectangle in Histogram && Maximal Rectangle
		1. Maximal Square 题目链接 题目要求: Given a 2D binary matrix filled with 0's and 1's, find the largest squa ... 
随机推荐
- 异步设备IO 《windows核心编程》第10章学习
			异步IO操作与同步操作区别: 在CreateFile里的FILE_FLAG_OVERLAPPED标志 异步操作函数LPOVERLAPPED参数 接收IO请求完成通知 触发设备内核对象 缺点:同一个设备 ... 
- 字符串表达式String Expressions
			声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ... 
- STORM_0009_Lifecycle-of-a-topology/拓扑的生命周期
			http://storm.apache.org/releases/1.0.1/Lifecycle-of-a-topology.html STORM拓扑的生命周期 本页的内容基于0.7.1代码,后来 ... 
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟
			D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ... 
- hdu 4217  Data Structure? 树状数组求第K小
			Data Structure? Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ... 
- DB2常识
			1.DB2组件 appendixa. db2 database product and packaging informatin一节AESE: 高级企业服务器版(Advanced enterprise ... 
- Json-lib使用  转载
			1.从Object到String 要先用Object对象构造一个JSONObject或者JSONArray对象,然后调用它的toString()方法即可 (1)示例一 1 Book book=new ... 
- web设计经验<七>13步打造优雅的WEB字体
			今天,大多数浏览器已经默认支持Web字体,日趋增多的字体特性被嵌入最新版HTML和CSS标准中,Web字体即将迎来一个趋于复杂的崭新时代.下面是一些基本的关于字体的规则,特别适用于Web字体. 原文地 ... 
- MySQL忘记root密码--skip-grant-tables
			使用--skip-grant-tables选项启动MYSQL时,服务器将不加载权限判断,这样就可以进行授权和密码更新操作了,具体步骤如下: 1. 停止mysql /etc/init.d/mysqld ... 
- JAVASCRIPT事件详解-------原生事件基础....
			javaScirpt事件详解-原生事件基础(一) 事件 JavaScript与HTML之间的交互是通过事件实现的.事件,就是文档或浏览器窗口中发生的一些特定的交互瞬间,通过监听特定事件的发生,你能 ... 
