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

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.

 

 1 public class Solution {
 2     public int MaximalSquare(char[,] matrix) {
 3         int rows = matrix.GetLength(0), cols = matrix.GetLength(1);
 4         
 5         var dp = new int[rows + 1, cols + 1];
 6         int max = 0;
 7         
 8         for (int i = 0; i < rows; i++)
 9         {
10             for (int j = 0; j < cols; j++)
11             {
12                 if (matrix[i, j] == '0')
13                 {
14                     dp[i + 1, j + 1] = 0;
15                 }
16                 else
17                 {
18                     dp[i + 1, j + 1] = Math.Min(Math.Min(dp[i, j + 1], dp[i + 1, j]), dp[i, j]) + 1;
19                     max = Math.Max(max, dp[i + 1, j + 1]);
20                 }
21             }
22         }
23         
24         return max * max;
25     }
26 }

 

转载于:https://www.cnblogs.com/liangmou/p/7953370.html

Snort源代码编译 _ 采坑之旅(for Windows VS2015)     系统环境:Windows7 sp1 x64     编译环境:VS2015 SP1     Snort版本:2.9.12     daq版本:2.0.6     Snort官网:https://www.snort.org/downloads#snort-downloads 背景     最近需要实现一个类似网络防火墙的产品,主要参考Snort源码,先花了点时间简单读了下网上比较流行的《... 阅读详情

相关推荐

FINN vs GFED vs GFAS vs QFED:四大火灾排放清单实战对比(含Python数据处理代码)

本文针对GFED、FINN、GFAS、QFED四大主流火灾排放清单,提供了实战对比分析与Python数据处理代码。通过量化对比东南亚农业火点与亚马逊雨林大火两个典型场景,揭示了不同清单在时空分辨率、算法内核和应用场景上的核心差异,并给出了基于研究目标、区域和模型的清单选择决策框架,帮助研究人员为空气质量模拟或火灾影响评估挑选最合适的数据源。

s3t4u的博客 430

leetcode 221: Maximal Square

leetcode 221: Maximal Square c++ python java

西施豆腐渣 1万+

Cloudflare SaaS 优选IP实战:提升大陆访问速度的配置指南

本文详细介绍了如何通过Cloudflare SaaS优选IP提升中国大陆用户访问速度的配置指南。从基础环境准备到IP筛选方法,再到完整配置流程和效果验证,帮助用户突破免费套餐限制,精准优化网络线路,特别适合跨境电商和面向中国大陆用户的网站优化。

weixin_29231027的博客 720

LeetCode:221 Maximal square

problem Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area solution 思路: 一个方正全是1,就是12and 22 and 32, 边长相等全是1, 怎么搜索才能是最优化的 先从最简单的暴力搜索开始分析,...

erzhushashade的博客 150

RK3588 部署 YOLO26 目标检测:PT → ONNX → RKNN 全流程

YOLO26n 在 RK3588 上 INT8 量化后 NPU 推理约 15ms,系统 FPS 约 55,可以覆盖边缘端实时检测需求。模型从 PT 到 RKNN 的转换要用opset=11避免算子兼容问题。先用 YOLO26n + 640 输入跑通全链路,确认推理结果正确后再做性能调优。

m0_64661770的博客 312

Android功耗系列专题分析之四:待机概率性功耗高的失效分析

本文分析了Android设备待机功耗异常高的问题。通过日志发现系统休眠失败,原因是PowerManagerService.Display唤醒锁未被释放。进一步排查发现,指纹解锁功能在灭屏时未正确释放屏幕锁定,导致DisplayReady状态异常。解决方案是将指纹功能的背光控制与DisplayReady状态控制分离,使用两个变量独立管理。经验表明,快速定位问题比解决问题更重要,修改原生流程时需谨慎评估风险。

459

LeetCode221:Maximal Square

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

3667

【C语言笔记初级篇】第一章:C语言快速入门及注意事项

(1)第一个C语言程序 A:利用vs2010写C语言程序 1:按以下步骤新建工程 2:添加源文件,“.c”文件 B:第一个C语言代码 1:以下是基本的C语言程序 2:由于没有设置连接器,所以打印结果没有显示,按照如下步骤链接控制台 (2)数据类型 A:基本数据类型及占用字节 B:一些概念的梳理 概念一:关于计算机的单位 位(bit):计算机通过电路的开关和闭合处理信息,电路通...

快乐江湖的博客 3750

LeetCode:221. Maximal Square

有一些需要我注意的点以及空间的优化方法。 1.常规dp class Solution { public: int maximalSquare(vector<vector<char>>& matrix) { if (matrix.empty() || matrix[0].empty()) return 0; ...

weixin_43462819的博客 153

Open3D DBSCAN聚类

DBSCAN算法做为一种有名的密度聚类算法,它是通过邻域参数(Distance,MinPts)来刻画样本分布的紧密程度。而在真正开始之前,首先要理解下面这几个概念:更为具体的内容也可参考这篇文章点云DBSCAN聚类算法。...

dayuhaitang1的博客 1803

YOLO11涨点优化:创新多尺度卷积注意力(MSCA)模块,小目标检测神器!

MSCA模块通过创新的多尺度设计,在保持计算效率的同时显著提升小目标检测能力。实验证明,在YOLOv5/v8等模型上嵌入MSCA后,mAP提升超过2%,小目标检测精度提升近4%,且计算代价增加极小。注意力机制的未来发展方向动态核尺寸:根据输入特征自适应调整卷积核大小跨模态融合:结合RGB与深度/热力图等多模态信息自监督优化:利用对比学习预训练注意力模块尝试在你的YOLO模型中插入MSCA模块,欢迎在评论区分享你的涨点结果!参考文献。

QQ_778132974的博客 479

LeetCode 221: Maximal Square

Maximal SquareGiven 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

一只码畜 332

mapbox进阶,百度地图、高德地图纠偏,使用在线网络地图加载插件

本文详细介绍如何基于mapbox-gl v3.8.0版本百度地图、高德地图纠偏,使用在线网络地图加载插件,亲测可用。希望能帮助到您。一起学习,加油!加油!

我哎GIS博客 757

LeetCode 221:Maximal Square 动态规划详解

这道题的价值不只是写出一个通过的答案,更重要的是:习惯用“以谁为结尾/为右下角”来定义状态。​这里有几个可以继续思考和练习的方向:能否自己实现一维滚动数组版本,把空间压到 O(n)?​能否类比这题,去看“最大矩形(Maximal Rectangle)”、“最大全 1 子矩阵”等题?​能否把“上、左、左上取 min + 1”这个模式,总结成一种“从相邻子问题扩张目标形状”的通用套路?​。

六六哥的博客 1386

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

LeetCode: 221. Maximal Square

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

杨领well的专栏 178

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

LeetCode221: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 LeetCode:链接 ...

卷卷萌的博客 237

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Leetcode: maximal square(221)

【代码】Leetcode: maximal square(221)

m0_73668537的博客 298

leetcode085_221:Maximal Rectangle&Maximal Square

题目描述 Maximal Rectangle: Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing all ones and return its area. Maximal Square Given a 2D binary matrix filled with 0’s a

devbarry的专栏 647

LeetCode题解:(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. 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 ...

weixin_30568715的博客 118

每周LeetCode算法题(八): 题目: 221. Maximal Square & 85. Maximal Rectangle

每周LeetCode算法题(八)题目1: 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. For example, given the following matri

JacKnights的博客 386

LeetCode : 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 代码 很好理解的动归。dp为以当...

心之所向 199

leetcode题解(六十二):221. Maximal Square

二维数组中找1构成的面积最大的矩形 Example: Input: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 Output: 4 public int maximalSquare(char[][] a) { if(a.length == 0) return 0; int m = a.length, n = a[0].length, result...

微博@山椒鱼只想坐在地上生根发芽 156

LeetCode(85 & 221):最大矩形 Maximal Rectangle & 最大正方形 Maximal Square(Java)

2019.10.14 #程序员笔试必备# LeetCode 从零单刷个人笔记整理(持续更新) github:https://github.com/ChopinXBP/LeetCode-Babel 这道题是之前做过的一道题的拓展题:LeetCode(84):柱状图中最大的矩形 Largest Rectangle in Histogram(Java) 从之前的解法思路出发可以有三种方法: 1.动态规...

NJU_ChopinXBP的博客 388
上一篇: Python解Leetcode: 725. Split Linked List in Parts
下一篇: 支付宝退款 (新版)
weixin_30877181
博客等级 码龄11年 135粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值