221. Maximal Square(动态规划)
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.
Example:
Input: 1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0 Output: 4
dp[i][j] = min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+1;
class Solution {
public:
int maximalSquare(vector<vector<char>>& matrix) {
int n = matrix.size();
if(n==) return ;
int m = matrix[].size();
vector<vector<int> > dp(n+,vector<int>(m+,));
int res =;
for(int i = ;i <=n;i++)
for(int j = ;j<=m;j++){
if(matrix[i-][j-]=='')
dp[i][j] = min(dp[i-][j-],min(dp[i-][j],dp[i][j-]))+;
res = max(res,dp[i][j]);
}
return res*res;
}
};
221. Maximal Square(动态规划)的更多相关文章
- leetcode每日解题思路 221 Maximal Square
问题描述: 题目链接:221 Maximal Square 问题找解决的是给出一个M*N的矩阵, 只有'1', '0',两种元素: 需要你从中找出 由'1'组成的最大正方形.恩, 就是这样. 我们看到 ...
- 求解最大正方形面积 — leetcode 221. Maximal Square
本来也想像园友一样,写一篇总结告别 2015,或者说告别即将过去的羊年,但是过去一年发生的事情,实在是出乎平常人的想象,也不具有代表性,于是计划在今年 6 月份写一篇 "半年总结" ...
- 【刷题-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 ...
- [LeetCode] 221. 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 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址: https://leet ...
- Java for LeetCode 221 Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...
- 221. Maximal Square -- 矩阵中1组成的最大正方形
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and re ...
- (medium)LeetCode 221.Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...
随机推荐
- Direct3D 11 Tutorial 3: Shaders and Effect System_Direct3D 11 教程3:着色器和效果系统
概述 在上一个教程中,我们设置了一个顶点缓冲区并将一个三角形传递给GPU. 现在,我们将逐步完成图形管道并查看每个阶段的工作原理. 将解释着色器和效果系统的概念. 请注意,本教程与前一个源代码共享相同 ...
- Kubernetes集群的监控报警策略最佳实践
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/M2l0ZgSsVc7r69eFdTj/article/details/79652064 本文为Kub ...
- spingboot中的美女banner.txt
.::::. .::::::::. ::::::::::: ..:::::::::::' '::::::::::::' .:::::::::: '::::::::::::::.. ..:::::::: ...
- ifconfig 中的 eth0 eth0:1 eth0.1 与 lo
1. eth0 eth0:1 eth0.1 eth0 eth0:1 和eth0.1三者的关系对应于物理网卡.子网卡.虚拟VLAN网卡的关系:物理网卡:物理网卡这里指的是服务器上实际的网络接口设备,这里 ...
- DOTween-Ease缓动函数
Ease.InQuad 不知道Quad代表什么意思 Ease.InQuart 有1/4的时间是没有缓动. Ease.InQuint, 是1/5时间没有缓动. Ease.InExpo 一直很平缓, ...
- eclipse输入中文为繁体字
今天上班在java类中写注释,发现是繁体字,于是切换到文本编辑器,简体字,于是百度发现, 原来是搜狗输入放和eclipse的快捷键ctrl+shift+F冲突,因为使用了eclipse的格式化,结果切 ...
- TIJ -- 吐司BlockingQueue
1. 吐司BlockingQueue 考虑下面这个使用BlockingQueue的示例.有一台机器具有三个任务:一个制作吐司,一个给吐司抹黄油,另一个在抹过黄油的吐司上吐果酱.我们可以通过各个处理过程 ...
- CentOS 6.8 防火墙配置
系统: CentOS release 6.8 (Final) iptables v1.4.7 执行命令: #清除所有规则 iptables -F #开放redis端口 iptables -A INPU ...
- ES6 扩展运算符 三点(...)
含义 扩展运算符( spread )是三个点(...).它好比 rest 参数的逆运算,将一个数组转为用逗号分隔的参数序列. console.log(...[, , ]) // 1 2 3 conso ...
- Java | 原来 serialVersionUID 的用处在这里
本文首发于 http://youngzy.com/ 一直不太明白Java对象里 serialVersionUID 字段是做什么用的.有或者没有,它们之间有差别吗?除了Eclipse里提示的那个黄色的警 ...