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 ...
随机推荐
- Android 获取外网IP,实测有效
网上有很多获取IP的例子,不过都是获取到的本地ip,还有的是因为走不通了,获取到的ip为空,下面看实测获取到外网IP的代码,注意需要在线程里面执行 /** * 获取外网的IP(要访问Url,要放到后台 ...
- .NET Core 2.1中的HttpClientFactory最佳实践
ASP.NET Core 2.1中出现一个新的HttpClientFactory功能, 它有助于解决开发人员在使用HttpClient实例从其应用程序发出外部Web请求时可能遇到的一些常见问题. 介绍 ...
- 火币网行情获取的websocket客户端
从验证结果看应该是网络关闭了,不过程序写的不错,可以作为其它websocket客户端的测试程序 # !/usr/bin/env python # -*- coding: utf-8 -*- # aut ...
- opencv利用直方图判断人脸光照质量
懒得用中文再写一遍了, 直接传送门过去吧. https://medium.com/@fanzongshaoxing/detect-face-in-bad-lighting-condition-usin ...
- mybatis batch批量提交大量数据
转载:https://blog.csdn.net/Java_Mr_Zheng/article/details/50476757 在xml文件配置多条参数同时插入: <insert id=&quo ...
- 使用redis原生list结构作为消息队列取代celery框架。
1.web后台对大批量的繁重的io任务需要解耦使用分布式异步技术,否则会使接口阻塞,并发延迟,一般就选celery好了.此篇的取代主要是针对取代celery的worker模式.没有涉及到周期和定时模式 ...
- Linux下">/dev/null 2>&1 "相关知识说明
在学习Linux的过程中,常会看到一些终端命令或者程序中有">/dev/null 2>&1"出现,由于已经遇到了好几次了,为了理解清楚,不妨花点时间百度或者go ...
- C_C++变量命名规则
变量命名规则是为了增强代码的可读性和容易维护性.以下为C++必须遵守的变量命名规则: 变量名只能是字母(A-Z,a-z)和数字(0-9)或者下划线(_)组成. 第一个字母必须是字母或者下划线开头. 不 ...
- [BTS] BizTalk EDI character set and separator settings
最近一个项目上遇到需要对EDI头.分隔符.小数点等配置项进行设置. 这里只记录一下结果,原理不记了,多看MSDN. UNB1中的信息在BizTalk中是不会体现在EDI输出文件中的,双方协商好即可. ...
- thinkphp5中使用PHPExcel(转载)
thinkphp5中可以使用composer来获取第三方类库,使用起来特别方便,例如:可是使用composer下载PHPMailer,think-captcha(验证码)等等…… 接下来说一下怎么使用 ...