Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.

For example, given the following matrix:

1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0

Return 4.

 class Solution {
public:
int maximalSquare(vector<vector<char>>& matrix) {
int n=matrix.size();
if(n<) return ;
int m=matrix[].size();
if(m<) return ;
vector<vector<int>> size(n,vector<int>(m,));
int maxnum=;
int i;
for(i=;i<n;i++)
{
if(matrix[i][]=='')
{
size[i][]=;
maxnum=;
}
}
for(i=;i<m;i++)
{
if(matrix[][i]=='')
{
size[][i]=;
maxnum=;
}
} int j;
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
if(matrix[i][j]=='')
{
size[i][j]=min(size[i-][j-],min(size[i-][j],size[i][j-]))+;
if(maxnum<size[i][j])
maxnum=size[i][j];
}
else
size[i][j]=;
}
}
return maxnum*maxnum;
}
};

Maximal Square的更多相关文章

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

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

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

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

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

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

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

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

  6. 【LeetCode】221. Maximal Square

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

  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] Maximal Square 最大正方形

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

  9. LeetCode Maximal Square

    原题链接在这里:https://leetcode.com/problems/maximal-square/ 这是一道DP题,存储历史信息是到当前点能有的最大square, 用二维数组dp存储. 更新方 ...

  10. LeetCode OJ 之 Maximal Square (最大的正方形)

    题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...

随机推荐

  1. android Java BASE64编码和解码二:图片的编码和解码

    1.准备工作 (1)在项目中集成 Base64 代码,集成方法见第一篇博文:android Java BASE64编码和解码一:基础 (2)添加 ImgHelper 工具类 package com.a ...

  2. 理解Lucene索引与搜索过程中的核心类

    理解索引过程中的核心类 执行简单索引的时候需要用的类有: IndexWriter.ƒDirectory.ƒAnalyzer.ƒDocument.ƒField 1.IndexWriter IndexWr ...

  3. android media server 解析1-media player service 结构部分

    下面为media server注册的四个服务之一:MediaPlayerService的结构图 1.图中没有MediaPlayerService的代理对象BpMediaPlayerService部分, ...

  4. 实验:传输层:TCP协议

    一.概述 TCP和UDP处在同一层——运输层,但是它们有很多的不同.TCP是TCP/IP系列协议中最复杂的部分,它具有以下特点: (1) TCP提供 可靠的 数据传输服务,TCP是 面向连接的 .应用 ...

  5. android学习笔记 Service

    Service(服务): 长期后台运行的没有界面的组件 android应用什么地方需要用到服务? 天气预报:后台的连接服务器的逻辑,每隔一段时间获取最新的天气信息.股票显示:后台的连接服务器的逻辑,每 ...

  6. Finder增强插件XtraFinder

    关于在Mac上安装XtraFinder插件,现在因为Mac更新到10.11, Mac OS X 10.11(El Capitan)默认开启了 SIP(System Integrity Protecti ...

  7. 很好的UI动效设计参考

    toolBar下拉:

  8. 手动方式安装 eclipse 的svn插件 Subversive和 Subversive SVN Connectors

      0.下载配置jdk 链接:http://pan.baidu.com/s/1miIVuic 密码:mwo7 配置 JAVA_HOME .JRE_HOME 1 下载eclipse       ecli ...

  9. json深度详解及org.json库

    了解json  (Javascript Object Notation) 网站:http://json.org/ english JSON (JavaScript Object Notation) i ...

  10. 单元测试_JUnit4的应用与实践

    本文实例为:JUnit4+Eclipse+CVS的实践 目录 1.测试环境搭建 1.1 JDK安装部署 1.2 Eclipse安装部署 1.3 Eclipse添加JUnit4 1.4 CVS项目文件引 ...