思路:

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. LOAP& its implimenlation

    LDAP 概念 LDAP的英文全称是Lightweight Directory Access Protocol,简称为LDAP,LDAP是轻量目录访问协议,LDAP是轻量目录访问协议.简单的说来,LD ...

  2. java.lang.NoClassDefFoundError: Could not initialize class异常处理

    借鉴:http://blog.csdn.net/sleepdancer/article/details/9207425 static { InputStream in = XXX.class.getR ...

  3. JDBC的存储过程

    以下内容引用自http://wiki.jikexueyuan.com/project/jdbc/stored-procedure.html: 正如一个Connection对象创建了Statement和 ...

  4. sum over使用方法,以及与group by的差别

    1.sum over使用方法 sum(col1) over(partition by col2 order by col3 ) 以上的函数能够理解为:按col2 进行分组(partition ),每组 ...

  5. psping

    psping工具功能主要包括:ICMP Ping.TCP Ping.延迟测试.带宽测试,是微软出品. 下载地址:https://download.sysinternals.com/files/PSTo ...

  6. firebug的应用

    firebug再前端调试中起到了非常好的作用能看到DOM的性能,以及检測.比方运用console.log()就是要比alert():好一些这样增强的页面的连续性而且console.warn()和con ...

  7. Chrome插件(扩展)

    [干货]Chrome插件(扩展)开发全攻略   写在前面 我花了将近一个多月的时间断断续续写下这篇博文,并精心写下完整demo,写博客的辛苦大家懂的,所以转载务必保留出处.本文所有涉及到的大部分代码均 ...

  8. jquery中怎样防止冒泡事件

    jquery中怎样防止冒泡事件 1.利用event.stopPropagation() 2.利用return false 3.利用event.preventDefault()

  9. Linux地址ping不通情况怎么办?

    查看原文:http://www.ibloger.net/article/325.html Linux地址ping不通情况怎么办? 问题:今天写了一个微信支付的项目.有一个class中使用了httpPo ...

  10. MyEclipse,Eclipse注释规范模板

    注释的作用:myeclipse中java文件头注释格式设置,最终可用于javadoc.exe生成API文档,同时提高了代码的可读性 设置方法: windows->preferences-> ...