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
class Solution {
public int maximalSquare(char[][] matrix) {
if (matrix == null || matrix.length == 0) {
return 0;
} int row = matrix.length;
int col = matrix[0].length;
int[][] sqr = new int[row + 1][col + 1];
int res = 0; for (int i = 1; i <= row; i++) {
for(int j = 1; j <= col; j++) {
if (matrix[i - 1][j - 1] == '1') {
sqr[i][j] = Math.min(Math.min(sqr[i - 1][j], sqr[i][j - 1]), sqr[i - 1][j - 1]) + 1;
res = Math.max(res, sqr[i][j]);
}
}
}
return res * res;
}
}

[LC] 221. Maximal Square的更多相关文章

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

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

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

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

  3. 【LeetCode】221. Maximal Square

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

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

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

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

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

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

  8. (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 ...

  9. 221. Maximal Square

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

随机推荐

  1. OA|DOAJ|Highwire press|Springeropen|Plos journal|电子印本|中国科技论文在线|arxiv|chinaxiv|MIT机构知识库|中科院机构知识库|Email alert|Citeseer|RSS|F1000 prime

    信息检索 OA:open access开放获取 金色OA:出版社主导, 开放出版,全部都可以下载. 开放论文:只有部分可以下载. 绿色OA:作者主导,发表后放在机构知识库中,排版不同,但是内容一致.E ...

  2. modbus 指令16 $10 的格式

    { //写多个请求 01(从设备)10(功能码) 00 77(起始地址) 00 01(寄存器数) 02(字节数) 05 55(写的数据) 6F B8(CRC) //写多个返回 01(从设备) 10(功 ...

  3. eclipse使用jetty服务器

    1.安装Eclipse Jetty插件: 2.下载jetty(9.4.6): 3.配置jetty运行设置: 右键项目 run configurations,选择jetty webapp,新建项目. c ...

  4. java 的HashMap底层数据结构

    HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以key-value的形式存在.在HashMap中,key-value总是会当做一个整体来处理,系统会根据 ...

  5. 静态页面缓存(thymeleaf模板writer)

    //前端html <!DOCTYPE html><html lang="en"> <head> <meta charset="U ...

  6. 使用Eclipse开发学习 Spring Boot 教程的内容小结

    spring-tool-suite使用教程,并创建spring配置文件 Spring Boot基础教程1-Spring Tool Suite工具的安装 Spring Boot基础教程2-RESTful ...

  7. tensorflow slim训练以及到安卓部署教程

    https://blog.csdn.net/chenyuping333/article/details/81537551 https://blog.csdn.net/u012328159/articl ...

  8. Python笔记_第一篇_面向过程_第一部分_5.Python数据类型之元组类型(tuple)

    元组!在Python中元组是属于列表的一种延伸,也是一种有序集合,成为一种只读列表,即数据可以被查找,不能被修改,列表的切片操作同样适用于元组. 特点:1. 与列表非常相似. 2. 一旦初始化就不能修 ...

  9. jdk8下载地址

    http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html Java SE Binaries ...

  10. jmlr论文下载

    下载脚本 #!/bin/bash # down_jmlr.sh ver=$1 wget http://www.jmlr.org/papers/$ver/ -O index.htm cat index. ...