思路:

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的更多相关文章

  1. 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 方法一 ...

  2. 求解最大正方形面积 — leetcode 221. Maximal Square

    本来也想像园友一样,写一篇总结告别 2015,或者说告别即将过去的羊年,但是过去一年发生的事情,实在是出乎平常人的想象,也不具有代表性,于是计划在今年 6 月份写一篇 "半年总结" ...

  3. [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 ...

  4. leetcode每日解题思路 221 Maximal Square

    问题描述: 题目链接:221 Maximal Square 问题找解决的是给出一个M*N的矩阵, 只有'1', '0',两种元素: 需要你从中找出 由'1'组成的最大正方形.恩, 就是这样. 我们看到 ...

  5. 【动态规划】leetcode - Maximal Square

    称号: Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square contain ...

  6. 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 ...

  7. 【LeetCode】221. Maximal Square

    Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square containing ...

  8. 【刷题-LeetCode】221. Maximal Square

    Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square containing ...

  9. [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 ...

随机推荐

  1. 应用CLR的线程池

    大家都知道这个线程的建立和销毁都需要很大的性能开销,当有比较多且不同的任务需要完成时,可以考虑使用线程池来管理这些线程.在以windows NT为内核的操作系统上每个进程都包含一个线程池,在线程池中存 ...

  2. Servlet的会话(Session)跟踪

    以下内容引用自http://wiki.jikexueyuan.com/project/servlet/session-tracking.html: HTTP是一种“无状态”协议,这意味着每次客户端检索 ...

  3. 基于 Java 的开源网络爬虫框架 WebCollector

    原文:https://www.oschina.net/p/webcollector

  4. SAS编程基础 - 菜鸟入门常用操作

    1. SAS9.4添加和取消注释的快捷键? Ctrl+/:添加注释 Ctrl+Shift+/:取消注释 2. 如何强制终止程序运行? 看到那个圆圈里带叹号的图标了吗?没错,就是它 - 中断! 3. 如 ...

  5. zabbix学习系列之配置邮件告警

    整体思路是:添加监控项-->配置触发器(达到设定的阈值就触发)-->配置动作(将某个触发器绑定到某个动作,达到某个阈值,触发器触发的时候,通过邮件发送告警信息给某个用户) 配置触发器 创建 ...

  6. Android进程间通信之内部类作为事件监听器

    在Android中,使用内部类能够在当前类里面发用改监听器类,由于监听器类是外部类的内部类.所以能够自由訪问外部类的全部界面组件. 下面是一个调用系统内部类实现短信发送的一个样例: SMS类: pac ...

  7. AutoCAD菜单加载失败 找不到文件mnc 怎么办

    菜单加载失败,找不到文件 SWFILECONV(mnu/mns/mnc)   找到CAD安装目录下的swfileconv.arx文件,用记事本打开,清空内容,然后保存即可.  

  8. HDU 2054 A == B ?(找小数点)

    题目链接:pid=2054" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=2054 Prob ...

  9. hdu5375 Gray code(DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5375 题目大意:给你一个二进制串,带'?'的位置能够由你来决定填'1'还是'0',补充完整之后转换成 ...

  10. JspSmartUpload 实现上传

    2.save  作用:将所有上传文件保存到指定文件夹下,并返回保存的文件个数. 原型:public int save(String destPathName)  和public int save(St ...