leetcode221 Maximal Square
思路:
dp。
实现:
class Solution
{
public:
int maximalSquare(vector<vector<char>>& matrix)
{
if (matrix.empty()) return ;
int m = matrix.size(), n = matrix[].size();
vector<int> dp(m, );
int maxn = ;
for (int i = ; i < m; i++)
{
dp[i] = matrix[i][] - '';
maxn = max(maxn, dp[i]);
}
for (int i = ; i < n; i++)
{
int pre = dp[];
dp[] = matrix[][i] - '';
maxn = max(dp[], maxn);
for (int j = ; j < m; j++)
{
if (matrix[j][i] == '')
{
pre = min(pre, min(dp[j - ], dp[j])) + ;
swap(dp[j], pre);
maxn = max(maxn, dp[j]);
}
else dp[j] = ;
}
}
return maxn * maxn;
}
};
leetcode221 Maximal Square的更多相关文章
- Leetcode221. Maximal Square最大正方形
在一个由 0 和 1 组成的二维矩阵内,找到只包含 1 的最大正方形,并返回其面积. 示例: 输入: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 输出: 4 方法一 ...
- 求解最大正方形面积 — leetcode 221. Maximal Square
本来也想像园友一样,写一篇总结告别 2015,或者说告别即将过去的羊年,但是过去一年发生的事情,实在是出乎平常人的想象,也不具有代表性,于是计划在今年 6 月份写一篇 "半年总结" ...
- [LintCode] Maximal Square 最大正方形
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...
- leetcode每日解题思路 221 Maximal Square
问题描述: 题目链接:221 Maximal Square 问题找解决的是给出一个M*N的矩阵, 只有'1', '0',两种元素: 需要你从中找出 由'1'组成的最大正方形.恩, 就是这样. 我们看到 ...
- 【动态规划】leetcode - Maximal Square
称号: Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square contain ...
- 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 ...
- 【LeetCode】221. Maximal Square
Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square containing ...
- 【刷题-LeetCode】221. Maximal Square
Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square containing ...
- [Swift]LeetCode221. 最大正方形 | Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and re ...
随机推荐
- MySQL集群方案收集
MySQL集群是一个需要时间才能磨得出的话题,不可能一下子就全部能掌握.由于整个方案结合LVS+Keepalived这种,更加的复杂. 下面是一些主流方案的收集: MySQL双主 + Keepaliv ...
- Linux学习系列之Inotify+Rsync实现实时数据同步
Inotify简介 inotify介绍 inotify是一种强大的.异步的文件系统监控机制,linux内核从2.6.13起,加入了inotify的支持,通过inotify可以监控文件系统中添加.删除. ...
- hdu 1565 方格取数(1)(状态压缩dp)
方格取数(1) Time Limit: 10000/5000 MS (J ...
- Android网络爬虫程序(基于Jsoup)
摘要:基于 Jsoup 实现一个 Android 的网络爬虫程序,抓取网页的内容并显示出来.写这个程序的主要目的是抓取海投网的宣讲会信息(公司.时间.地点)并在移动端显示,这样就可以随时随地的浏览在学 ...
- git 在一台机器上配置多个账户
前提: 必须知道怎样配置git账户,请參考git官方教程:https://help.github.com/articles/generating-ssh-keys 这个教程能教你怎样生成ssh-key ...
- 【Android基础】App签名与打包
签名的意义 1. 为了保证程序开发人员的合法 2. 防止部分人通过使用同样的Package Name(包名)来混淆替换已安装的程序 3. 保证我们每次公布的版本号的一致性(保证签名一致才干升级) 签名 ...
- 使用qemu
1 获取qemu启动linux kernel的log qemu-system-x86_64 -nographic -kernel xxx -initrd xxx -append "conso ...
- document.body.className = document.body.className.replace("siteorigin-panels-before-js","");
document.body.className = document.body.className.replace("siteorigin-panels-before-js",&q ...
- 内容原发网站seo不重视2个标签,导致seo效果不如转发网站
采集数据,挖掘观点,小心求证,得出结论 时间经过 今日凌晨,爬虫热点采集,其中第一财经是目标站之一,采集到了 http://www.yicai.com/news/5391233.html 谷歌去年悄然 ...
- (转)web会话管理方式
阅读目录 1. 基于server端session的管理 2. cookie-based的管理方式 3. token-based的管理方式 4. 安全问题 5. 总结 http是无状态的,一次请求结束, ...