当前位置:网站首页>leetcode:221. Maximum square [essence of DP state transition]
leetcode:221. Maximum square [essence of DP state transition]
2022-07-05 13:01:00 【White speed Dragon King's review】
analysis
dp[i][j] Said to (i, j) Is the largest square side length in the lower right corner
The first row and the first column are special
Other words need to consider the essence formula :
dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
It's the essence of the world
ac code
class Solution:
def maximalSquare(self, matrix: List[List[str]]) -> int:
ans = 0
# dp[i][j] Said to (i, j) It is the largest collection in the lower right corner 1 Square area
m, n = len(matrix), len(matrix[0])
dp = [[0] * n for _ in range(m)]
for i in range(m):
for j in range(n):
if matrix[i][j] == '1':
if i == 0 or j == 0:
dp[i][j] = 1
else:
# quintessence
dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
ans = max(ans, dp[i][j] * dp[i][j])
return ans
summary
dp tricks
About finding one that's all 1 The largest square of
边栏推荐
- Association modeling method in SAP segw transaction code
- 初次使用腾讯云,解决只能使用webshell连接,不能使用ssh连接。
- 【云原生】Nacos中的事件发布与订阅--观察者模式
- Difference between JUnit theories and parameterized tests
- What if wechat is mistakenly sealed? Explain the underlying logic of wechat seal in detail
- RHCSA2
- SAP SEGW 事物码里的导航属性(Navigation Property) 和 EntitySet 使用方法
- 国内市场上的BI软件,到底有啥区别
- Setting up sqli lab environment
- 使用 jMeter 对 SAP Spartacus 进行并发性能测试
猜你喜欢
Distance measuring sensor chip 4530a used in home intelligent lighting
stm32和电机开发(从架构图到文档编写)
CVPR 2022 | single step 3D target recognizer based on sparse transformer
A deep long article on the simplification and acceleration of join operation
Introduction to sap ui5 flexiblecolumnlayout control
研究:数据安全工具在 60% 的情况下无法抵御勒索软件
潘多拉 IOT 开发板学习(HAL 库)—— 实验7 窗口看门狗实验(学习笔记)
Get to know linkerd project for the first time
Hiengine: comparable to the local cloud native memory database engine
SAP UI5 FlexibleColumnLayout 控件介绍
随机推荐
Pinduoduo flag insertion remarks API
MySQL 巨坑:update 更新慎用影响行数做判断!!!
Setting up sqli lab environment
开发者,云原生数据库是未来吗?
uni-app开发语音识别app,讲究的就是简单快速。
946. Verify stack sequence
研究:数据安全工具在 60% 的情况下无法抵御勒索软件
Kotlin variable
How can non-technical departments participate in Devops?
百日完成国产数据库opengausss的开源任务--openGuass极简版3.0.0安装教程
简单上手的页面请求和解析案例
潘多拉 IOT 开发板学习(HAL 库)—— 实验7 窗口看门狗实验(学习笔记)
RHCSA7
SAP UI5 DynamicPage 控件介紹
Discussion on error messages and API versions of SAP ui5 getsaplogonlanguage is not a function
I met Tencent in the morning and took out 38K, which showed me the basic smallpox
Introduction to sap ui5 flexiblecolumnlayout control
Taobao product details API | get baby SKU, main map, evaluation and other API interfaces
Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
【Nacos云原生】阅读源码第一步,本地启动Nacos