leetcode 日经贴,Cpp code -Maximal Rectangle
来源:互联网 发布:油田网络宽带客服电话 编辑:程序博客网 时间:2024/06/07 09:35
Maximal Rectangle
class Solution {public: int maxhis(const vector<int> hist) { stack<pair<int,int> > st; int maxarea = 0; for (int i = 0; i <= hist.size(); ++i) { int h = i == hist.size() ? -1:hist[i]; if (st.empty() || st.top().first < h) { st.push(make_pair(h, i)); } else { int lastp = i; while (!st.empty() && st.top().first >= h) { maxarea = max(maxarea, (i - st.top().second) * st.top().first); lastp = st.top().second; st.pop(); } st.push(make_pair(h, lastp)); } } return maxarea; } int maximalRectangle(vector<vector<char> > &matrix) { int n = matrix.size(); if (n == 0) return 0; int m = matrix[0].size(); if (m == 0) return 0; vector<int> hist(m, 0); int marea = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { hist[j] = matrix[i][j]=='1'? hist[j] + 1: 0; } int ca = maxhis(hist); marea = max(ca, marea); } return marea; }};
0 0
- leetcode 日经贴,Cpp code -Maximal Rectangle
- leetcode 日经贴,Cpp code -Maximal Square
- Leetcode 85. Maximal Rectangle (Hard) (cpp)
- leetcode 日经贴,Cpp code -Largest Rectangle in Histogram
- CODE 48: Maximal Rectangle
- maximal-rectangle Java code
- 【LeetCode】Maximal Rectangle && Maximal Square
- Leetcode:Maximal Square & Maximal Rectangle
- LeetCode: Maximal Rectangle
- LeetCode Maximal Rectangle
- LeetCode: Maximal Rectangle
- [LeetCode] Maximal Rectangle
- [leetcode] Maximal Rectangle
- [LeetCode]Maximal Rectangle
- [leetcode]Maximal Rectangle
- LeetCode-Maximal Rectangle
- [leetcode] Maximal Rectangle
- Leetcode Maximal Rectangle
- 机器学习实战ByMatlab(五)Logistic Regression
- RQNOJ252 公司聚会 题解。
- 一个C++的内存池和内存管理的实现(六)
- HDU 3697 Selecting courses 选课(AC代码)贪心
- C# 使用Xamarin 开发应用 -- 切换Activity
- leetcode 日经贴,Cpp code -Maximal Rectangle
- Maximum number of format records exceeded. Using default format
- ADT/Eclipse上 使用SVN管理项目基本流程
- Softmax回归C++实现
- Deep Learning by Andrew Ng --- Sparse coding
- C# 使用Xamarin 开发应用 -- Alert Box
- RQNOJ57 AC之后~~
- 靠大数据赚钱的10个例子(转载)
- css中的糟粕