当前位置:网站首页>Sword finger offer II 040 Largest rectangle in matrix
Sword finger offer II 040 Largest rectangle in matrix
2022-06-29 04:12:00 【Python ml】
The finger of the sword Offer II 040. The largest rectangle in the matrix
class Solution:
def largestRectangleArea(heights: List[int]) -> int:
heights.append(0) # The height of the last column is 0, All the remaining elements of the list will pop Calculate the maximum rectangular area when it is height
lenh=len(heights)
maxArea=0
h=[-1]
for i in range (lenh):
while h[-1]!=-1 and heights[i]<heights[h[-1]]:
area_height=heights[h[-1]]
h.pop()
area_width=i-h[-1]-1 # When there is only one column element left , Left boundary index It can be regarded as -1
maxArea=max(maxArea,area_height*area_width)
h.append(i) # here heights[i]>heights[h[-1]]
return maxArea
def maximalRectangle(self, matrix: List[str]) -> int:
if not matrix:
return 0
row,col=len(matrix),len(matrix[0])
height,ans=[0]*col,0
for i in range(row):
for j in range (col):
if matrix[i][j]=='0':
height[j]=0
elif i>0 and matrix[i-1][j]=='0': # The rest and matrix[i][j]=1 and matrix[i-1][j]=0
height[j]=int(matrix[i][j])
else: # first line And matrix[i][j]=1 Or The rest And matrix[i][j]=1 And matrix[i-1][j]=1
height[j]+=1
ans=max(ans,Solution.largestRectangleArea(height))
return ans
边栏推荐
- 二叉树序列化与反序列化(leetcode(困难))
- 科技云报道:混合办公的B面:安全与效率如何兼得?
- Logstash starts too slowly or even gets stuck
- Zhai Jia: from technical engineer to open source entrepreneur of "net red"
- PostgreSQL has a cross database references are not implemented bug
- 1018 锤子剪刀布
- Runtimeerror in yolox: dataloader worker (PID (s) 17724, 1364, 18928) exited unexpectedly
- 1015 德才论
- 百度智能云服务网格产品CSM发布 | 火热公测中
- 赚钱的5个层次,你在哪一层?
猜你喜欢

Wi-Fi 7 来啦,它到底有多强?

在命令行登录mysql数据库以及查看版本号

Remote connection of raspberry pie in VNC Viewer Mode

选对学校,专科也能进华为~早知道就好了

SqlServer如何查询除去整列字段为null的结果

The five levels of making money, which level are you on?

你为什么做测试/开发程序员?还能回想出来吗......
![[C language] address of stack memory associated with local variable 'num' returned](/img/34/f8cf86a18ed461b25073b740dece45.png)
[C language] address of stack memory associated with local variable 'num' returned

Rapid development project -vscode plug-in

【滤波器设计】根据设计指标使用matlab定制滤波器
随机推荐
How to keep database and cache consistent
sql数据库存储过程写法
Nuxt - 每个页面单独设置 SEO 相关标签及网页标题、图标等(页面配置 head)
[filter design] customize the filter with MATLAB according to the design index
【FPGA+sin】基于DDS(直接数字合成)的正弦信号发生器模块FPGA实现
Developer scheme · environmental monitoring equipment (Xiaoxiong school IOT development board) connected to graffiti IOT development platform
1018 锤子剪刀布
How to back up all data on Apple mobile phone in 2 steps (free)
Redis 缓存穿透、缓存击穿、缓存雪崩
iNFTnews | 元宇宙技术将带来全新的购物体验
SEAttention 通道注意力机制
Why is the test post a giant pit? The 8-year-old tester told you not to be fooled
PostgreSQL 出现cross-database references are not implemented的bug
我的创作纪念日
Cloud native weekly | grafana 9 was officially released; The Chinese version of cloud native vocabulary is now online
2022年 6月27号 《暑假感悟篇一》路程的选择权。
人民银行印发《关于支持外贸新业态跨境人民币结算的通知》
JSX的基本使用
【C语言】开启一个线程
Pytorch read / write file