思路:

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. Ubuntu 16.04安装WebStorm

    前提:必须正确安装JDK. 下载: http://confluence.jetbrains.com/display/WI/WebStorm+EAP 或者下载历史版本:https://www.jetbr ...

  2. 携程Apollo(阿波罗)配置中心在Spring Boot项目快速集成

    前提:先搭建好本地的单机运行项目:http://www.cnblogs.com/EasonJim/p/7643630.html 说明:下面的示例是基于Spring Boot搭建的,对于Spring项目 ...

  3. OJ-online judegement

    OJ-online judegement https://baike.baidu.com/item/OJ/8129019?fr=aladdin

  4. 文件权限的获取,cmd命令:Takeown

    takeown /f * /a /r /d y #强制将当前目录下的所有文件及文件夹.子文件夹下的所有者更改为管理员组(administrators)命令: cacls d:documents*.* ...

  5. nyist oj 19 擅长排列的小明(dfs搜索+STL)

    擅长排列的小明 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描写叙述 小明十分聪明.并且十分擅长排列计算.比方给小明一个数字5,他能立马给出1-5按字典序的全排列,假设你想 ...

  6. HDU 4923 Room and Moor(瞎搞题)

    瞎搞题啊.找出1 1 0 0这样的序列,然后存起来,这样的情况下最好的选择是1的个数除以这段的总和. 然后从前向后扫一遍.变扫边进行合并.每次合并.合并的是他的前驱.这样到最后从t-1找出的那条链就是 ...

  7. linux一些硬件详情查看的高级方法(网卡,内存,硬盘,cpu)

    网卡-lspci内存大小和个数—— dmidecode|grep -A16 "Memory Device$"查看硬盘型号——smartctl -a /dev/sda查看硬盘大小—— ...

  8. UVA - 11374 Airport Express (Dijkstra模板+枚举)

    Description Problem D: Airport Express In a small city called Iokh, a train service, Airport-Express ...

  9. tesnorflow Conv2DTranspose

    tensorflow/python/layers/convolutional.py # Infer the dynamic output shape: out_height = utils.decon ...

  10. python的一些常用函数

    1 filter(function, iterable) 等价于(item for item in iterable if function(item)) 就是说,filter会遍历iterable中 ...