[LC] 221. Maximal Square
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的更多相关文章
- leetcode每日解题思路 221 Maximal Square
问题描述: 题目链接:221 Maximal Square 问题找解决的是给出一个M*N的矩阵, 只有'1', '0',两种元素: 需要你从中找出 由'1'组成的最大正方形.恩, 就是这样. 我们看到 ...
- 求解最大正方形面积 — leetcode 221. Maximal Square
本来也想像园友一样,写一篇总结告别 2015,或者说告别即将过去的羊年,但是过去一年发生的事情,实在是出乎平常人的想象,也不具有代表性,于是计划在今年 6 月份写一篇 "半年总结" ...
- 【LeetCode】221. Maximal Square
Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square containing ...
- 【刷题-LeetCode】221. Maximal Square
Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square containing ...
- [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 ...
- 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 ...
- 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 ...
- (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 ...
- 221. Maximal Square
题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...
随机推荐
- 开发大型项目必备 98%公司都在用的十佳 Java Web 应用框架
众所周知,工欲善其事,必先利其器.选择一个好的 Web 应用框架就像一把称手的兵器,可以助大家披荆斩棘. 今天就为大家整理了十佳 Java Web 应用框架,并简单讨论一下它们的优缺点. 第一,大名鼎 ...
- Python—程序设计:抽象工厂模式
抽象工厂模式 内容:定义一个工厂类接口,让工厂子类来创建一系列相关或相互依赖的对象. 例:生产一部手机,需要手机壳.CPU.操作系统三类对象进行组装,其中每类对象都有不同的种类.对每个具体工厂,分别生 ...
- MJJ玩磁铁
题目: Problem D: MJJ玩磁铁 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 139 Solved: 9[Submit][Status][ ...
- Express+MySQL实现图片上传到服务器并把路径保存到数据库中
demo准备:mysql5.7.20 express4.0 处理图片文件的中间件Multer 先搭建服务器并展示html页面 const express = require("express ...
- 基于Struts2开发公司职工管理系统 Java源码
开发环境: Windows操作系统 开发工具: MyEclipse+Jdk+Tomcat+MySql数据库 职工管理系统作为一种管理软件正在各公司中得到越来越广泛的应用,且已达到了良好效果. 运行效果 ...
- PAT Advanced 1069 The Black Hole of Numbers (20) [数学问题-简单数学]
题目 For any 4-digit integer except the ones with all the digits being the same, if we sort the digits ...
- let和var的区别
在JavaScript中,定义变量的关键词一般用var,但还有一种定义变量的关键词叫let.两者的作用域范围不一样,我们可以将var理解为定义的是一个全局变量,而let定义的是一个局部变量.故let常 ...
- SVN常见错误解决办法和批量add等命令
批量添加所有更改文件 svn add . --no-ignore --force 提交文件 svn commit -m "up" File already exists: file ...
- Django_前介
Django 1.软件框架 一个公司是由公司中的各部部门来组成的,每一个部门拥有特定的职能,部门与部门之间通过相互的配合来完成让公司运转起来. 一个软件框架是由其中各个软件模块组成的,每一个模 ...
- 阿里云ECS搭建邮件服务
安装mailx [root@db ~]# yum install -y mailx [root@db ~]# vim /etc/mail.rc 设置发件人信息 ..... set from=yunwe ...