LeetCode Maximal Rectangle

LeetCode刷题:85. Maximal Rectangle LeetCode刷题:85. Maximal Rectangle 原题链接:https://leetcode.com/problems/maximal-rectangle/ Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its... 阅读详情

原题链接在这里:https://leetcode.com/problems/maximal-rectangle/

与Largest Rectangle in Histogram相似. 用一个数组dp存储一行中每一个点的最大高度,然后像Largest Rectangle in Histogram算这一行能产生的最大面积maxRec.

Time O(m*n), m是matrix的高,n是matrix的长。Space O(n).

AC Java:

public class Solution {
    public int maximalRectangle(char[][] matrix) {
        if(matrix == null || matrix.length == 0 || matrix[0].length == 0){
            return 0;
        }
        int h = matrix.length;
        int w = matrix[0].length;
        // length,length,length,length,length
        int [] dp = new int[w];
        int maxRec = 0;
        for(int i = 0; i<h; i++){
            for(int j=0; j<w; j++){
                dp[j] = matrix[i][j] == '0' ? 0 : dp[j]+1;
            }
            maxRec = Math.max(maxRec,helper(dp));
        }
        return maxRec;
    }
    private int helper(int [] nums){
        if(nums == null || nums.length == 0){
            return 0;
        }
        Stack<Integer> stk = new Stack<Integer>();
        int [] h = new int[nums.length + 1];
        h = Arrays.copyOf(nums, nums.length+1);
        int maxArea = 0;
        
        int i = 0;
        while(i<h.length){
            if(stk.isEmpty() || h[stk.peek()] <= h[i]){
                stk.push(i);
                i++;
            }else{
                int index = stk.pop();
                maxArea = Math.max(maxArea,h[index]*(stk.isEmpty() ? i : i-stk.peek()-1));
            }
        }
        return maxArea;
    }
}


全球最大光伏电池缺陷异常检测数据集PVELAD【发布】 下载地址 1:GitHub - binyisu/PVEL-AD 下载地址 2:http://aihebut.com/col.jsp?id=118 下载地址 3:NAVEDownload 竞赛测试系统:Photovoltaic cell anomaly detection | Kaggle 一、简介 PVEL-AD 数据集又叫做EL2021数据集是用于对光伏电池异常缺陷检测方法进行基准测试的数据集,重点是光伏电池工业检测。PVEL-AD包含 36,543 张具有各种内部缺陷和异构背... 阅读详情

相关推荐

华大HC32F460 TCP Server实验

华大HC32F460 TCP Server实验

ZhuoWuKeJi的博客 1270

【LeetCode】Maximal Rectangle

参考链接 http://blog.youkuaiyun.com/littlestream9527/article/details/19641013 题目描述 题目分析 总结 代码示例 推荐学习C++的资料 C++标准函数库 http://download.youkuaiyun.com/detail/chinasnowwolf/71

Snowwolf_Yang的程序化生活 649

RealSense D435i深度相机实战:从像素坐标到三维空间的精准映射(Python实现)

本文详细介绍了使用RealSense D435i深度相机实现从二维像素坐标到三维空间坐标精准映射的两种Python实战方法:深度图反投影法与点云直接查找法。文章涵盖环境搭建、相机对齐、代码实现、性能对比及与YOLO等检测模型结合的进阶应用,并提供了关键的避坑指南和参数调优建议,帮助开发者在机器人、三维重建等项目中高效应用。

weixin_29291573的博客 382

[leetcode]Maximal Square 和 Maximal Rectangle

刚好在实际应用中碰到了类似问题,大致内容是需要求一个不规则区域的最大可用的矩形区域,当时的想法是首先获得不规则区域的外接矩形,矩形的某一条边与该区域的最长的一条边重叠,然后将外接矩形划分成很多个网格,判断每个网格是否处在区域中,在则置为1,不在为0,再求最大的都为1的矩形区域(与Maximal Rectangle问题类似)。 Maximal Square int maximalSquare(vec...

willaoo的博客 209

数据库实验报告--MySQL

数据库完整版报告--MySQL 包括数据库创建、表的创建、视图以及授权和触发器的创建等内容,全是精华!看完点赞加收藏O(∩_∩)O~。

Mortalz7 4924

情感分析在金融领域的应用:舆情影响股价预测

我们都知道,股价的波动受到多种因素的影响,而大众的情绪和看法就是其中很重要的一部分。我们在日常生活中都有根据别人的评价来判断事物好坏的经验,在金融市场里,舆情就像是大众对某家公司的集体评价,它能反映出市场参与者的情绪和预期。学习这方面的知识,能帮助投资者更好地把握市场动态,做出更明智的投资决策,无论是个人投资者还是金融机构的分析师,都能从中受益。有一天,你看到某家知名企业被曝光了严重的产品质量问题,新闻铺天盖地,股民们也都在热议纷纷,负面情绪弥漫。这时,你会不会觉得这家公司的股价可能要下跌了呢?

AI 原生应用开发的博客 1145

Leetcode:Maximal Square & Maximal Rectangle

url : https://leetcode.com/problems/maximal-square/description/url : https://leetcode.com/problems/maximal-rectangle/description/解题思路: Maximal Square 此题相对简单,使用动态规划。 matrix[i,j]==0时, dp[i,j]=0; matrix[

zhumingyuan111的博客 370

WRFDA如何读取风云四号A 星的GIIRS数据?

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值。

**My Coding Family** 1025

[LeetCode 84, 85]Largest Rectangle in Histogram / Maximal Rectangle

LeetCode第84,85号题,解题报告。利用栈的O(n)算法

zlasd的博客 423

用Python爬取大连商品交易所期货实时行情:从入门到实战

python复制编辑# utils.py"豆粕": "M0","铁矿石": "I0","聚乙烯": "L0","玉米": "C0","聚丙烯": "PP0","棕榈油": "P0"本项目展示了:✅ 如何从新浪财经 API获取主力合约实时数据✅ 使用Python异步爬虫技术) 提升效率✅ 利用pandas和matplotlib进行结构化分析与可视化✅ 具备良好的扩展性,可对接金融、农业、能源等数据需求场景✅ 可作为期货量化策略数据源✅ 可嵌入自动化报告系统。

2201_76125261的博客 1247

数字孪生教程大全之 我们如何构建数字孪生?数字孪生的五个级别都是什么

文章摘要 什么是数字孪生? 我们如何构建数字孪生? 开发智能数字孪生系统的框架 什么是数字孪生? 数字孪生是一个不言自明的术语,用于识别物理系统的数字化版本。数字孪生的最早参考来自大卫·格伦特(David Gelernter )的小说作品。在他 1995 年的书中,Gelernter 博士为读者提供了未来有趣的可能性——万维网。前网络书籍谈到了计算机系统上的镜像数字世界。有些人可能会争辩说,我们的 Meta-verse 是新的数字世界——现实世界的数字孪生。但是,还有其他可能性,时间可能会讲述一个更好的

iCloudEnd的博客 3629

【DP】LeetCode 85. Maximal Rectangle

LeetCode 85. Maximal Rectangle Solution1: 一语惊醒梦中人啊,参考链接:https://www.youtube.com/watch?v=2Yk3Avrzauk 根据第84题完成! class Solution { public: int maximalRectangle(vector&amp;amp;lt;vector&amp;amp;lt;char&amp;amp;gt;&amp;amp;gt;&amp;amp

Allenlzcoder的博客 338

Devexpress16.2.6破解工具

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

leetcode:Maximal Rectangle

这是leetcode的第85题,原题如下:Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing all ones and return its area.leetcode的第84题是Largest Rectangle in Histogram,原题如下: 解决方案在http

不积跬步,无以至千里 1778

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

leetcode难题之Maximal Rectangle

一,题目简述 leetcode第85题,Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. 在一个只含有0和1的二维矩阵中,找出只含有1的最大矩形并返回其面积。 二,题目分析 在解决这一道题之前,让...

lishinho的博客 281

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

[LeetCode] Maximal Rectangle

[Problem] Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area. [Analysis] 和 Largest Rectangle in Histogram 的方法比较相似,对于矩阵的每一个点,确定该点能够向上达

1.02^365的成长裂变 3624

[leetCode] 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. public class Solution { public int maximalRectangle(char[][] matrix) {

QihaoD的专栏 482

leetcode Maximal Rectangle

Description: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. For example, given the following matrix: 1 0 1 0 0 1 0 1 1 1

qq_33755214的博客 184

Leetcode之Maximal Rectangle

题目: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. Example: Input: [ ["1","0","1","0","0"], ["1","0","1","1","1"], ["1"...

qq_35455503的博客 204

LeetCode Maximal rectangle

动态规划。我自己第一遍做没做出来,上网搜了一下答案,发现是用的之前合并方块的思路做得。 就是这样。每次统计每行累计1的个数,然后计算出每行的最大直方图面积。 那么代码是如下所示: public class Solution { public int maximalRectangle(char[][] matrix) { if(matrix==null || matrix.length

input1991的专栏 332

[leetcode] Maximal Rectangle

Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area. 能跑的通所有测试用例的$n^3$,$n^4$解法

粉刷匠 450

[LeetCode]Maximal Rectangle

class Solution { //here we compute the most far range(both in height, and width) of scan line j at every row i //to get the size of the rectangle of f[i][j]. To achieve this, we should compute: //H[j]

孙佰贵的专栏 2481

LeetCode85——Maximal Rectangle

初看这道题有点不知所措,但是其实是LeetCode84——Largest Rectangle in Histogram的一个变形。

上善若水 2372

LeetCode 85. Maximal Rectangle

题目来源:https://leetcode.com/problems/maximal-rectangle/ 问题描述 85.Maximal Rectangle Hard Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return it...

da_kao_la的博客 189

【Leetcode】85. Maximal Rectangle

这样我们可以只存一维数组然后逐行递推即可。的个数(也就是柱的高度),那么有。为底的最大高度,然后就可以套用。求一遍最大矩形面积即可。组成的最大矩形的面积。首先,我们可以对每一行。

数学、算法爱好者的博客 183

leetcode 84.Largest Rectangle in Histogram, 85.Maximal Rectangle

leetcode 84.Largest Rectangle in Histogram(Hard) leetcode 85.Maximal Rectangle(Hard)

liquewei_26的博客 376
上一篇: LeetCode Largest Rectangle in Histogram
下一篇: LeetCode Longest Valid Parentheses
Dylan_Java_NYC
博客等级 码龄11年 1粉丝 134原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值