leetcode 日经贴,Cpp code -Maximal Square
来源:互联网 发布:centos查看防火墙端口 编辑:程序博客网 时间:2024/06/06 00:04
Maximal Square
class Solution {public: int maxhist(vector<int> &hist) { int n = hist.size(); int maxarea = 0; stack<pair<int, int> > st; st.push(make_pair(-1, -1)); for (int i = 0; i <= n; ++i) { int h = i < n? hist[i]:0; int p = i; while (!st.empty() && st.top().first >= h) { p = st.top().second; int t = min(st.top().first, i - p); maxarea = max(maxarea, t * t); st.pop(); } st.push(make_pair(h, p)); } return maxarea; } int maximalSquare(vector<vector<char>>& matrix) { vector<int> vi; int n = matrix.size(); if (n == 0) return 0; int m = matrix[0].size(); if (m == 0) return 0; vi.resize(m); int maxarea = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m ;++j) { if (matrix[i][j] == '1') { vi[j]++; } else { vi[j] = 0; } } int t = maxhist(vi); maxarea = max(maxarea, t); } return maxarea; }};
0 0
- leetcode 日经贴,Cpp code -Maximal Square
- leetcode 日经贴,Cpp code -Maximal Rectangle
- Leetcode 221. Maximal Square (Medium) (cpp)
- 【LeetCode】Maximal Rectangle && Maximal Square
- Leetcode:Maximal Square & Maximal Rectangle
- [leetcode] Maximal Square
- Maximal Square Leetcode Java
- [leetcode] Maximal Square
- leetcode 221: Maximal Square
- LeetCode Maximal Square
- Maximal Square - LeetCode 221
- #leetcode#Maximal Square
- LeetCode Maximal Square
- [LeetCode] Maximal Square
- [LeetCode]Maximal Square
- leetcode Maximal Square
- leetcode Maximal Square
- Leetcode 221 Maximal Square
- UNIX/Linux函数lseek说明
- IOS实现多媒体音频之音乐播放器
- 数据结构与算法(单循环链表)
- 垃圾回收的finalize方法使用
- HDOJ 寻找素数对 1262
- leetcode 日经贴,Cpp code -Maximal Square
- A. Toy Cars
- 魔狼地址:https://bitbucket.org/moLangZaiShi/demo/downloads
- 百度地图SDK 详解 应用(官方)
- 垃圾收集算法
- Oracle学习(十一)之使用RMAN对数据库做在线完全备份
- gdb调试ns3出现的问题-找不到库
- ios一些关键字
- MFC:判断点(POINT)是否在某一区域(CRect)