当前位置:网站首页>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
边栏推荐
- ##无监控,不运维,以下是监控里常用的脚本监控
- SAP SEGW 事物码里的导航属性(Navigation Property) 和 EntitySet 使用方法
- 国内市场上的BI软件,到底有啥区别
- How to connect the API interface of Taobao open platform (super detailed)
- Install rhel8.2 virtual machine
- 10 minute fitness method reading notes (2/5)
- 初次使用腾讯云,解决只能使用webshell连接,不能使用ssh连接。
- Tips and tricks of image segmentation summarized from 39 Kabul competitions
- MySQL 巨坑:update 更新慎用影响行数做判断!!!
- 石臻臻的2021总结和2022展望 | 文末彩蛋
猜你喜欢

Notes for preparation of information system project manager --- information knowledge

SAP UI5 ObjectPageLayout 控件使用方法分享

I'm doing open source in Didi

2021.12.16-2021.12.20 empty four hand transaction records

DNS的原理介绍

Taobao short video, why the worse the effect

无密码身份验证如何保障用户隐私安全?

Four common problems of e-commerce sellers' refund and cash return, with solutions

Natural language processing series (I) introduction overview

SAP UI5 DynamicPage 控件介绍
随机推荐
Vonedao solves the problem of organizational development effectiveness
开发者,云原生数据库是未来吗?
HiEngine:可媲美本地的云原生内存数据库引擎
Association modeling method in SAP segw transaction code
阿里云SLB负载均衡产品基本概念与购买流程
10 minute fitness method reading notes (2/5)
Notes for preparation of information system project manager --- information knowledge
CVPR 2022 | single step 3D target recognizer based on sparse transformer
10 minute fitness method reading notes (3/5)
Introduction aux contrôles de la page dynamique SAP ui5
RHCSA3
2021-12-21 transaction record
Taobao order interface | order flag remarks, may be the most stable and easy-to-use interface
Wechat enterprise payment to change access, open quickly
【Nacos云原生】阅读源码第一步,本地启动Nacos
实战模拟│JWT 登录认证
A deep long article on the simplification and acceleration of join operation
#yyds干货盘点#js截取文件后缀名
SAP UI5 ObjectPageLayout 控件使用方法分享
将函数放在模块中